diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-04-25 20:53:07 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-04-25 20:53:07 +0200 |
commit | 34d3074847f2182e1ba7922207e5f8790b9bd581 (patch) | |
tree | 04c2c1264da848238882a8f6c2a07a6555d842ad | |
parent | 1547d20ff3b8ec57fbd62fcd7348758b8c103232 (diff) |
Replace the multipurpose VespaXMLFeeder.Operation with more to the point classes with proper final members.
16 files changed, 139 insertions, 154 deletions
diff --git a/document/src/main/java/com/yahoo/document/json/JsonFeedReader.java b/document/src/main/java/com/yahoo/document/json/JsonFeedReader.java index f773173e89a..be4aa6cfb41 100644 --- a/document/src/main/java/com/yahoo/document/json/JsonFeedReader.java +++ b/document/src/main/java/com/yahoo/document/json/JsonFeedReader.java @@ -9,9 +9,11 @@ import com.yahoo.document.DocumentPut; import com.yahoo.document.DocumentRemove; import com.yahoo.document.DocumentTypeManager; import com.yahoo.document.DocumentUpdate; +import com.yahoo.vespaxmlparser.DocumentFeedOperation; +import com.yahoo.vespaxmlparser.DocumentUpdateFeedOperation; import com.yahoo.vespaxmlparser.FeedOperation; import com.yahoo.vespaxmlparser.FeedReader; -import com.yahoo.vespaxmlparser.VespaXMLFeedReader.Operation; +import com.yahoo.vespaxmlparser.RemoveFeedOperation; /** @@ -37,25 +39,21 @@ public class JsonFeedReader implements FeedReader { @Override public FeedOperation read() throws Exception { DocumentOperation documentOperation = reader.next(); - Operation operation = new Operation(); if (documentOperation == null) { stream.close(); - return operation; + return FeedOperation.INVALID; } if (documentOperation instanceof DocumentUpdate) { - operation.setDocumentUpdate((DocumentUpdate) documentOperation); + return new DocumentUpdateFeedOperation((DocumentUpdate) documentOperation, documentOperation.getCondition()); } else if (documentOperation instanceof DocumentRemove) { - operation.setRemove(documentOperation.getId()); + return new RemoveFeedOperation(documentOperation.getId(), documentOperation.getCondition()); } else if (documentOperation instanceof DocumentPut) { - operation.setDocument(((DocumentPut) documentOperation).getDocument()); + return new DocumentFeedOperation(((DocumentPut) documentOperation).getDocument(), documentOperation.getCondition()); } else { throw new IllegalStateException("Got unknown class from JSON reader: " + documentOperation.getClass().getName()); } - - operation.setCondition(documentOperation.getCondition()); - return operation; } } diff --git a/document/src/main/java/com/yahoo/document/json/SingleDocumentParser.java b/document/src/main/java/com/yahoo/document/json/SingleDocumentParser.java index 8012ebafb13..28aa9ed1d8d 100644 --- a/document/src/main/java/com/yahoo/document/json/SingleDocumentParser.java +++ b/document/src/main/java/com/yahoo/document/json/SingleDocumentParser.java @@ -7,7 +7,9 @@ import com.yahoo.document.DocumentPut; import com.yahoo.document.DocumentTypeManager; import com.yahoo.document.DocumentUpdate; import com.yahoo.document.json.document.DocumentParser; -import com.yahoo.vespaxmlparser.VespaXMLFeedReader; +import com.yahoo.vespaxmlparser.DocumentFeedOperation; +import com.yahoo.vespaxmlparser.DocumentUpdateFeedOperation; +import com.yahoo.vespaxmlparser.FeedOperation; import java.io.IOException; import java.io.InputStream; @@ -25,32 +27,26 @@ public class SingleDocumentParser { this.docMan = docMan; } - public VespaXMLFeedReader.Operation parsePut(InputStream inputStream, String docId) { + public FeedOperation parsePut(InputStream inputStream, String docId) { return parse(inputStream, docId, DocumentParser.SupportedOperation.PUT); } - public VespaXMLFeedReader.Operation parseUpdate(InputStream inputStream, String docId) { + public FeedOperation parseUpdate(InputStream inputStream, String docId) { return parse(inputStream, docId, DocumentParser.SupportedOperation.UPDATE); } - private VespaXMLFeedReader.Operation parse(InputStream inputStream, String docId, DocumentParser.SupportedOperation supportedOperation) { + private FeedOperation parse(InputStream inputStream, String docId, DocumentParser.SupportedOperation supportedOperation) { final JsonReader reader = new JsonReader(docMan, inputStream, jsonFactory); final DocumentOperation documentOperation = reader.readSingleDocument(supportedOperation, docId); - VespaXMLFeedReader.Operation operation = new VespaXMLFeedReader.Operation(); try { inputStream.close(); } catch (IOException e) { throw new RuntimeException(e); } if (supportedOperation == DocumentParser.SupportedOperation.PUT) { - operation.setDocument(((DocumentPut) documentOperation).getDocument()); + return new DocumentFeedOperation(((DocumentPut) documentOperation).getDocument(), documentOperation.getCondition()); } else { - operation.setDocumentUpdate((DocumentUpdate) documentOperation); + return new DocumentUpdateFeedOperation((DocumentUpdate) documentOperation, documentOperation.getCondition()); } - - // (A potentially empty) test-and-set condition is always set by JsonReader - operation.setCondition(documentOperation.getCondition()); - - return operation; } } diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/ConditionalFeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/ConditionalFeedOperation.java index c512c004efb..e7a06560532 100644 --- a/document/src/main/java/com/yahoo/vespaxmlparser/ConditionalFeedOperation.java +++ b/document/src/main/java/com/yahoo/vespaxmlparser/ConditionalFeedOperation.java @@ -1,4 +1,21 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespaxmlparser; -public class ConditionalFeedOperation { +import com.yahoo.document.TestAndSetCondition; + +public class ConditionalFeedOperation extends FeedOperation { + private final TestAndSetCondition condition; + protected ConditionalFeedOperation(Type type) { + super(type); + this.condition = TestAndSetCondition.NOT_PRESENT_CONDITION; + } + protected ConditionalFeedOperation(Type type, TestAndSetCondition condition) { + super(type); + this.condition = condition; + } + + @Override + public TestAndSetCondition getCondition() { + return condition; + } } diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java index 6efdfc2547a..f3ddbc9196c 100644 --- a/document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java +++ b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java @@ -1,4 +1,23 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespaxmlparser; -public class DocumentFeedOperation { +import com.yahoo.document.Document; +import com.yahoo.document.TestAndSetCondition; + +public class DocumentFeedOperation extends ConditionalFeedOperation { + private final Document document; + public DocumentFeedOperation(Document document) { + super(Type.DOCUMENT); + this.document = document; + } + + public DocumentFeedOperation(Document document, TestAndSetCondition condition) { + super(Type.DOCUMENT, condition); + this.document = document; + } + + @Override + public Document getDocument() { + return document; + } } diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java index 91cfcb955fe..af20d72a4e2 100644 --- a/document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java +++ b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java @@ -1,4 +1,22 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespaxmlparser; -public class DocumentUpdateFeedOperation { +import com.yahoo.document.DocumentUpdate; +import com.yahoo.document.TestAndSetCondition; + +public class DocumentUpdateFeedOperation extends ConditionalFeedOperation { + private final DocumentUpdate update; + public DocumentUpdateFeedOperation(DocumentUpdate update) { + super(Type.UPDATE); + this.update = update; + } + public DocumentUpdateFeedOperation(DocumentUpdate update, TestAndSetCondition condition) { + super(Type.UPDATE, condition); + this.update = update; + } + + @Override + public DocumentUpdate getDocumentUpdate() { + return update; + } } diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java index 58371faeced..9da3408da61 100644 --- a/document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java +++ b/document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java @@ -1,3 +1,4 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespaxmlparser; import com.yahoo.document.Document; @@ -5,13 +6,11 @@ import com.yahoo.document.DocumentId; import com.yahoo.document.DocumentUpdate; import com.yahoo.document.TestAndSetCondition; -public abstract class FeedOperation { +public class FeedOperation { public enum Type {DOCUMENT, REMOVE, UPDATE, INVALID} + public static final FeedOperation INVALID = new FeedOperation(Type.INVALID); private Type type; - protected FeedOperation() { - this(Type.INVALID); - } protected FeedOperation(Type type) { this.type = type; } @@ -20,9 +19,9 @@ public abstract class FeedOperation { this.type = type; } - public abstract Document getDocument(); - public abstract DocumentUpdate getDocumentUpdate(); - public abstract DocumentId getRemove(); + public Document getDocument() { return null; } + public DocumentUpdate getDocumentUpdate() { return null; } + public DocumentId getRemove() { return null; } public TestAndSetCondition getCondition() { return TestAndSetCondition.NOT_PRESENT_CONDITION; diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java index 8acd8506d0b..782a6295ee1 100644 --- a/document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java +++ b/document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java @@ -1,4 +1,22 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespaxmlparser; -public class RemoveFeedOperation { +import com.yahoo.document.DocumentId; +import com.yahoo.document.TestAndSetCondition; + +public class RemoveFeedOperation extends ConditionalFeedOperation { + private final DocumentId documentId; + public RemoveFeedOperation(DocumentId documentId) { + super(Type.REMOVE); + this.documentId = documentId; + } + public RemoveFeedOperation(DocumentId documentId, TestAndSetCondition condition) { + super(Type.REMOVE, condition); + this.documentId = documentId; + } + + @Override + public DocumentId getRemove() { + return documentId; + } } diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java b/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java index e34f3e7e4e4..7bc0cc871ca 100644 --- a/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java +++ b/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java @@ -75,70 +75,6 @@ public class VespaXMLFeedReader extends VespaXMLReader implements FeedReader { } /** - * Represents a feed operation found by the parser. Can be one of the following types: - * - getType() == DOCUMENT: getDocument() is valid. - * - getType() == REMOVE: getRemove() is valid. - * - getType() == UPDATE: getUpdate() is valid. - */ - public static class Operation extends FeedOperation { - - private Document doc; - private DocumentId remove; - private DocumentUpdate docUpdate; - private TestAndSetCondition condition = TestAndSetCondition.NOT_PRESENT_CONDITION; - - public Operation() { - setInvalid(); - } - - public void setInvalid() { - doc = null; - remove = null; - docUpdate = null; - condition = TestAndSetCondition.NOT_PRESENT_CONDITION; - } - - @Override - public Document getDocument() { - return doc; - } - - public void setDocument(Document doc) { - setType(Type.DOCUMENT); - this.doc = doc; - } - - @Override - public DocumentId getRemove() { - return remove; - } - - public void setRemove(DocumentId remove) { - setType(Type.REMOVE); - this.remove = remove; - } - @Override - public DocumentUpdate getDocumentUpdate() { - return docUpdate; - } - - public void setDocumentUpdate(DocumentUpdate docUpdate) { - setType(Type.UPDATE); - this.docUpdate = docUpdate; - } - - public void setCondition(TestAndSetCondition condition) { - this.condition = condition; - } - - @Override - public TestAndSetCondition getCondition() { - return condition; - } - - } - - /** * <p>Reads all operations from the XML stream and puts into a list. Note * that if the XML stream is large, this may cause out of memory errors, so * make sure to use this only with small streams.</p> @@ -162,7 +98,6 @@ public class VespaXMLFeedReader extends VespaXMLReader implements FeedReader { */ @Override public FeedOperation read() throws Exception { - Operation operation = new Operation(); String startTag = null; try { while (reader.hasNext()) { @@ -174,36 +109,28 @@ public class VespaXMLFeedReader extends VespaXMLReader implements FeedReader { if ("document".equals(startTag)) { VespaXMLDocumentReader documentReader = new VespaXMLDocumentReader(reader, docTypeManager); Document document = new Document(documentReader); - operation.setDocument(document); - operation.setCondition(TestAndSetCondition.fromConditionString(documentReader.getCondition())); - return operation; + return new DocumentFeedOperation(document, TestAndSetCondition.fromConditionString(documentReader.getCondition())); } else if ("update".equals(startTag)) { VespaXMLUpdateReader updateReader = new VespaXMLUpdateReader(reader, docTypeManager); DocumentUpdate update = new DocumentUpdate(updateReader); - operation.setDocumentUpdate(update); - operation.setCondition(TestAndSetCondition.fromConditionString(updateReader.getCondition())); - return operation; + return new DocumentUpdateFeedOperation(update, TestAndSetCondition.fromConditionString(updateReader.getCondition())); } else if ("remove".equals(startTag)) { - boolean documentIdFound = false; + DocumentId documentId = null; Optional<String> condition = Optional.empty(); for (int i = 0; i < reader.getAttributeCount(); i++) { final String attributeName = reader.getAttributeName(i).toString(); if ("documentid".equals(attributeName) || "id".equals(attributeName)) { - operation.setRemove(new DocumentId(reader.getAttributeValue(i))); - documentIdFound = true; + documentId = new DocumentId(reader.getAttributeValue(i)); } else if ("condition".equals(attributeName)) { condition = Optional.of(reader.getAttributeValue(i)); } } - if (!documentIdFound) { + if (documentId == null) { throw newDeserializeException("Missing \"documentid\" attribute for remove operation"); } - - operation.setCondition(TestAndSetCondition.fromConditionString(condition)); - - return operation; + return new RemoveFeedOperation(documentId, TestAndSetCondition.fromConditionString(condition)); } else { throw newDeserializeException("Element \"" + startTag + "\" not allowed in this context"); } @@ -222,7 +149,7 @@ public class VespaXMLFeedReader extends VespaXMLReader implements FeedReader { throw(e); } - return operation; + return FeedOperation.INVALID; } } diff --git a/vespa_feed_perf/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java b/vespa_feed_perf/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java index 9e32033634a..1377468e782 100644 --- a/vespa_feed_perf/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java +++ b/vespa_feed_perf/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java @@ -30,8 +30,11 @@ import com.yahoo.messagebus.SourceSessionParams; import com.yahoo.messagebus.StaticThrottlePolicy; import com.yahoo.messagebus.network.rpc.RPCNetworkParams; import com.yahoo.messagebus.routing.Route; +import com.yahoo.vespaxmlparser.DocumentFeedOperation; +import com.yahoo.vespaxmlparser.DocumentUpdateFeedOperation; import com.yahoo.vespaxmlparser.FeedReader; import com.yahoo.vespaxmlparser.FeedOperation; +import com.yahoo.vespaxmlparser.RemoveFeedOperation; import com.yahoo.vespaxmlparser.VespaXMLFeedReader; import net.jpountz.xxhash.XXHashFactory; @@ -226,10 +229,9 @@ public class SimpleFeeder implements ReplyHandler { } @Override public FeedOperation read() throws Exception { - VespaXMLFeedReader.Operation operation = new VespaXMLFeedReader.Operation(); int read = in.read(prefix); if (read != prefix.length) { - return operation; + return FeedOperation.INVALID; } ByteBuffer header = ByteBuffer.wrap(prefix); int sz = header.getInt(); @@ -246,15 +248,14 @@ public class SimpleFeeder implements ReplyHandler { } DocumentDeserializer deser = DocumentDeserializerFactory.createHead(mgr, GrowableByteBuffer.wrap(blob)); if (type == DOCUMENT) { - operation.setDocument(new Document(deser)); + return new DocumentFeedOperation(new Document(deser)); } else if (type == UPDATE) { - operation.setDocumentUpdate(new DocumentUpdate(deser)); + return new DocumentUpdateFeedOperation(new DocumentUpdate(deser)); } else if (type == REMOVE) { - operation.setRemove(new DocumentId(deser)); + return new RemoveFeedOperation(new DocumentId(deser)); } else { throw new IllegalArgumentException("Unknown operation " + type); } - return operation; } } 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<String> route) throws RestApiException; + void put(RestUri restUri, FeedOperation data, Optional<String> route) throws RestApiException; - void update(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException; + void update(RestUri restUri, FeedOperation data, Optional<String> route) throws RestApiException; void delete(RestUri restUri, String condition, Optional<String> 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<String> route) throws RestApiException { + public void put(RestUri restUri, FeedOperation data, Optional<String> 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<String> route) throws RestApiException { + public void update(RestUri restUri, FeedOperation data, Optional<String> 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<Boolean> create) { - final VespaXMLFeedReader.Operation operationUpdate = - singleDocumentParser.parseUpdate(request.getData(), id); + private FeedOperation createUpdateOperation(HttpRequest request, String id, String condition, Optional<Boolean> 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<String> route) throws RestApiException { + public void put(RestUri restUri, FeedOperation data, Optional<String> 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<String> route) throws RestApiException { + public void update(RestUri restUri, FeedOperation data, Optional<String> 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<SharedSourceSession> 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; } } diff --git a/vespaclient-core/src/main/java/com/yahoo/feedapi/Feeder.java b/vespaclient-core/src/main/java/com/yahoo/feedapi/Feeder.java index a2bb2e8514b..19d074a0ead 100644 --- a/vespaclient-core/src/main/java/com/yahoo/feedapi/Feeder.java +++ b/vespaclient-core/src/main/java/com/yahoo/feedapi/Feeder.java @@ -12,7 +12,6 @@ import javax.xml.stream.XMLStreamException; import com.yahoo.document.DocumentTypeManager; import com.yahoo.vespaxmlparser.FeedOperation; import com.yahoo.vespaxmlparser.FeedReader; -import com.yahoo.vespaxmlparser.VespaXMLFeedReader; /** * Base class for unpacking document operation streams and pushing to feed |