From 34d3074847f2182e1ba7922207e5f8790b9bd581 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 25 Apr 2019 20:53:07 +0200 Subject: Replace the multipurpose VespaXMLFeeder.Operation with more to the point classes with proper final members. --- .../yahoo/document/restapi/OperationHandler.java | 6 +++--- .../document/restapi/OperationHandlerImpl.java | 5 +++-- .../yahoo/document/restapi/resource/RestApi.java | 22 +++++++++++----------- .../restapi/resource/MockedOperationHandler.java | 5 +++-- .../vespa/http/server/V3CongestionTestCase.java | 5 ++--- .../java/com/yahoo/vespaxmlparser/MockReader.java | 20 ++++++-------------- 6 files changed, 28 insertions(+), 35 deletions(-) (limited to 'vespaclient-container-plugin') diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandler.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandler.java index cfa77455f41..a6fdcb10a00 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandler.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandler.java @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.restapi; -import com.yahoo.vespaxmlparser.VespaXMLFeedReader; +import com.yahoo.vespaxmlparser.FeedOperation; import java.util.Optional; @@ -90,9 +90,9 @@ public interface OperationHandler { VisitResult visit(RestUri restUri, String documentSelection, VisitOptions options) throws RestApiException; - void put(RestUri restUri, VespaXMLFeedReader.Operation data, Optional route) throws RestApiException; + void put(RestUri restUri, FeedOperation data, Optional route) throws RestApiException; - void update(RestUri restUri, VespaXMLFeedReader.Operation data, Optional route) throws RestApiException; + void update(RestUri restUri, FeedOperation data, Optional route) throws RestApiException; void delete(RestUri restUri, String condition, Optional route) throws RestApiException; diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java index bfc4a611a5e..b9bbe4f792e 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java @@ -25,6 +25,7 @@ import com.yahoo.messagebus.StaticThrottlePolicy; import com.yahoo.metrics.simple.MetricReceiver; import com.yahoo.vdslib.VisitorOrdering; import com.yahoo.vespaclient.ClusterDef; +import com.yahoo.vespaxmlparser.FeedOperation; import com.yahoo.vespaxmlparser.VespaXMLFeedReader; import com.yahoo.yolean.concurrent.ConcurrentResourcePool; import com.yahoo.yolean.concurrent.ResourceFactory; @@ -201,7 +202,7 @@ public class OperationHandlerImpl implements OperationHandler { } @Override - public void put(RestUri restUri, VespaXMLFeedReader.Operation data, Optional route) throws RestApiException { + public void put(RestUri restUri, FeedOperation data, Optional route) throws RestApiException { SyncSession syncSession = syncSessions.alloc(); Response response; try { @@ -225,7 +226,7 @@ public class OperationHandlerImpl implements OperationHandler { } @Override - public void update(RestUri restUri, VespaXMLFeedReader.Operation data, Optional route) throws RestApiException { + public void update(RestUri restUri, FeedOperation data, Optional route) throws RestApiException { SyncSession syncSession = syncSessions.alloc(); Response response; try { diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java index 880ea2102ab..873b0569553 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java @@ -33,6 +33,8 @@ import com.yahoo.vespa.config.content.LoadTypeConfig; import com.yahoo.vespa.config.content.AllClustersBucketSpacesConfig; import com.yahoo.vespaclient.ClusterDef; import com.yahoo.vespaclient.ClusterList; +import com.yahoo.vespaxmlparser.DocumentFeedOperation; +import com.yahoo.vespaxmlparser.FeedOperation; import com.yahoo.vespaxmlparser.VespaXMLFeedReader; import java.io.IOException; @@ -236,23 +238,21 @@ public class RestApi extends LoggingRequestHandler { return new Response(200, resultJson, Optional.of(restUri)); } - private VespaXMLFeedReader.Operation createPutOperation(HttpRequest request, String id, String condition) { - final VespaXMLFeedReader.Operation operationPut = - singleDocumentParser.parsePut(request.getData(), id); + private FeedOperation createPutOperation(HttpRequest request, String id, String condition) { + FeedOperation put = singleDocumentParser.parsePut(request.getData(), id); if (condition != null && ! condition.isEmpty()) { - operationPut.setCondition(new TestAndSetCondition(condition)); + return new DocumentFeedOperation(put.getDocument(), new TestAndSetCondition(condition)); } - return operationPut; + return put; } - private VespaXMLFeedReader.Operation createUpdateOperation(HttpRequest request, String id, String condition, Optional create) { - final VespaXMLFeedReader.Operation operationUpdate = - singleDocumentParser.parseUpdate(request.getData(), id); + private FeedOperation createUpdateOperation(HttpRequest request, String id, String condition, Optional create) { + FeedOperation update = singleDocumentParser.parseUpdate(request.getData(), id); if (condition != null && ! condition.isEmpty()) { - operationUpdate.getDocumentUpdate().setCondition(new TestAndSetCondition(condition)); + update.getDocumentUpdate().setCondition(new TestAndSetCondition(condition)); } - create.ifPresent(c -> operationUpdate.getDocumentUpdate().setCreateIfNonExistent(c)); - return operationUpdate; + create.ifPresent(c -> update.getDocumentUpdate().setCreateIfNonExistent(c)); + return update; } private HttpResponse handleGet(RestUri restUri, HttpRequest request) throws RestApiException { diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java index fbaa7f86bd0..1e982c7b700 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java @@ -5,6 +5,7 @@ import com.yahoo.document.restapi.OperationHandler; import com.yahoo.document.restapi.Response; import com.yahoo.document.restapi.RestApiException; import com.yahoo.document.restapi.RestUri; +import com.yahoo.vespaxmlparser.FeedOperation; import com.yahoo.vespaxmlparser.VespaXMLFeedReader; import java.util.Optional; @@ -31,13 +32,13 @@ public class MockedOperationHandler implements OperationHandler { @Override @SuppressWarnings("deprecation") - public void put(RestUri restUri, VespaXMLFeedReader.Operation data, Optional route) throws RestApiException { + public void put(RestUri restUri, FeedOperation data, Optional route) throws RestApiException { log.append("PUT: " + data.getDocument().getId()); log.append(data.getDocument().getBody().toString()); } @Override - public void update(RestUri restUri, VespaXMLFeedReader.Operation data, Optional route) throws RestApiException { + public void update(RestUri restUri, FeedOperation data, Optional route) throws RestApiException { log.append("UPDATE: " + data.getDocumentUpdate().getId()); log.append(data.getDocumentUpdate().fieldUpdates().toString()); if (data.getDocumentUpdate().getCreateIfNonExistent()) { diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V3CongestionTestCase.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V3CongestionTestCase.java index 106dd71b83c..04b66480a82 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V3CongestionTestCase.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V3CongestionTestCase.java @@ -18,8 +18,8 @@ import com.yahoo.messagebus.shared.SharedMessageBus; import com.yahoo.messagebus.shared.SharedSourceSession; import com.yahoo.metrics.simple.MetricReceiver; import com.yahoo.vespa.http.client.core.Headers; +import com.yahoo.vespaxmlparser.FeedOperation; import com.yahoo.vespaxmlparser.MockFeedReaderFactory; -import com.yahoo.vespaxmlparser.VespaXMLFeedReader; import org.junit.Before; import org.junit.Test; @@ -45,8 +45,7 @@ public class V3CongestionTestCase { ClientFeederWithMocks(ReferencedResource sourceSession, FeedReaderFactory feedReaderFactory, DocumentTypeManager docTypeManager, String clientId, Metric metric, ReplyHandler feedReplyHandler, AtomicInteger threadsAvailableForFeeding) { super(sourceSession, feedReaderFactory, docTypeManager, clientId, metric, feedReplyHandler, threadsAvailableForFeeding); // The operation to return from the client feeder. - VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation(); - docOp = DocumentOperationMessageV3.newRemoveMessage(op, "operation id"); + docOp = DocumentOperationMessageV3.newRemoveMessage(FeedOperation.INVALID, "operation id"); } diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespaxmlparser/MockReader.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespaxmlparser/MockReader.java index 606d21c0059..eabbb2dab20 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/vespaxmlparser/MockReader.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/vespaxmlparser/MockReader.java @@ -7,7 +7,6 @@ import com.yahoo.document.DocumentType; import com.yahoo.document.DocumentUpdate; import com.yahoo.vespa.http.server.MetaStream; import com.yahoo.vespa.http.server.util.ByteLimitedInputStream; -import com.yahoo.vespaxmlparser.VespaXMLFeedReader.Operation; import java.io.InputStream; import java.lang.reflect.Field; @@ -46,9 +45,8 @@ public class MockReader implements FeedReader { @Override public FeedOperation read() throws Exception { - Operation operation = new Operation(); if (finished) { - return operation; + return FeedOperation.INVALID; } byte whatToDo = stream.getNextOperation(); @@ -56,22 +54,16 @@ public class MockReader implements FeedReader { DocumentType docType = new DocumentType("banana"); switch (whatToDo) { case 0: - finished = true; - break; + return FeedOperation.INVALID; case 1: - Document doc = new Document(docType, id); - operation.setDocument(doc); - break; + return new DocumentFeedOperation(new Document(docType, id)); case 2: - operation.setRemove(id); - break; + return new RemoveFeedOperation(id); case 3: - operation.setDocumentUpdate(new DocumentUpdate(docType, id)); - break; - case 4: + return new DocumentUpdateFeedOperation(new DocumentUpdate(docType, id)); + default: throw new RuntimeException("boom"); } - return operation; } } -- cgit v1.2.3