diff options
Diffstat (limited to 'vespaclient-container-plugin')
2 files changed, 23 insertions, 31 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/DocumentOperationMessageV3.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/DocumentOperationMessageV3.java index a12fe4efa8b..6613f1a5538 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/DocumentOperationMessageV3.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/DocumentOperationMessageV3.java @@ -1,9 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.http.server; -import com.yahoo.document.DocumentPut; -import com.yahoo.document.DocumentRemove; -import com.yahoo.document.DocumentUpdate; import com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage; import com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage; import com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage; @@ -35,46 +32,44 @@ class DocumentOperationMessageV3 { } private static DocumentOperationMessageV3 newUpdateMessage(FeedOperation op, String operationId) { - DocumentUpdate update = op.getDocumentUpdate(); - update.setCondition(op.getCondition()); - Message msg = new UpdateDocumentMessage(update); + var msg = new UpdateDocumentMessage(op.getDocumentUpdate()); - String id = (operationId == null) ? update.getId().toString() : operationId; + String id = (operationId == null) ? msg.getDocumentUpdate().getId().toString() : operationId; return new DocumentOperationMessageV3(id, msg); } static DocumentOperationMessageV3 newRemoveMessage(FeedOperation op, String operationId) { - DocumentRemove remove = new DocumentRemove(op.getRemove()); - remove.setCondition(op.getCondition()); - Message msg = new RemoveDocumentMessage(remove); + var msg = new RemoveDocumentMessage(op.getDocumentRemove()); - String id = (operationId == null) ? remove.getId().toString() : operationId; + String id = (operationId == null) ? msg.getDocumentId().toString() : operationId; return new DocumentOperationMessageV3(id, msg); } private static DocumentOperationMessageV3 newPutMessage(FeedOperation op, String operationId) { - DocumentPut put = new DocumentPut(op.getDocument()); - put.setCondition(op.getCondition()); - Message msg = new PutDocumentMessage(put); + var msg = new PutDocumentMessage(op.getDocumentPut()); - String id = (operationId == null) ? put.getId().toString() : operationId; + String id = (operationId == null) ? msg.getDocumentPut().getId().toString() : operationId; return new DocumentOperationMessageV3(id, msg); } static DocumentOperationMessageV3 create(FeedOperation operation, String operationId, Metric metric) { switch (operation.getType()) { - case DOCUMENT: + case DOCUMENT -> { metric.add(MetricNames.NUM_PUTS, 1, null); return newPutMessage(operation, operationId); - case REMOVE: + } + case REMOVE -> { metric.add(MetricNames.NUM_REMOVES, 1, null); return newRemoveMessage(operation, operationId); - case UPDATE: + } + case UPDATE -> { metric.add(MetricNames.NUM_UPDATES, 1, null); return newUpdateMessage(operation, operationId); - default: + } + default -> { // typical end of feed return null; + } } } 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 c751849b84e..c6f48b6ae47 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 @@ -3,6 +3,8 @@ package com.yahoo.vespaxmlparser; import com.yahoo.document.Document; import com.yahoo.document.DocumentId; +import com.yahoo.document.DocumentPut; +import com.yahoo.document.DocumentRemove; import com.yahoo.document.DocumentType; import com.yahoo.document.DocumentUpdate; import com.yahoo.vespa.http.server.MetaStream; @@ -52,18 +54,13 @@ public class MockReader implements FeedReader { byte whatToDo = stream.getNextOperation(); DocumentId id = new DocumentId("id:banana:banana::doc1"); DocumentType docType = new DocumentType("banana"); - switch (whatToDo) { - case 0: - return FeedOperation.INVALID; - case 1: - return new DocumentFeedOperation(new Document(docType, id)); - case 2: - return new RemoveFeedOperation(id); - case 3: - return new DocumentUpdateFeedOperation(new DocumentUpdate(docType, id)); - default: - throw new RuntimeException("boom"); - } + return switch (whatToDo) { + case 0 -> FeedOperation.INVALID; + case 1 -> new DocumentFeedOperation(new DocumentPut(new Document(docType, id))); + case 2 -> new RemoveFeedOperation(new DocumentRemove(id)); + case 3 -> new DocumentUpdateFeedOperation(new DocumentUpdate(docType, id)); + default -> throw new RuntimeException("boom"); + }; } } |