diff options
11 files changed, 178 insertions, 156 deletions
diff --git a/document/abi-spec.json b/document/abi-spec.json index ca06e2547d7..ca4b4da3ca0 100644 --- a/document/abi-spec.json +++ b/document/abi-spec.json @@ -2862,7 +2862,8 @@ "methods" : [ "public abstract void write(com.yahoo.document.Document)", "public abstract void write(com.yahoo.document.DocumentId)", - "public abstract void write(com.yahoo.document.DocumentType)" + "public abstract void write(com.yahoo.document.DocumentType)", + "public abstract void write(com.yahoo.document.DocumentRemove)" ], "fields" : [ ] }, @@ -3104,6 +3105,7 @@ "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.annotation.AnnotationReference)", "public void write(com.yahoo.document.DocumentId)", "public void write(com.yahoo.document.DocumentType)", + "public void write(com.yahoo.document.DocumentRemove)", "public void write(com.yahoo.document.annotation.Annotation)", "public void write(com.yahoo.document.annotation.SpanTree)", "public void write(com.yahoo.document.annotation.SpanNode)", diff --git a/document/src/main/java/com/yahoo/document/json/JsonSerializationHelper.java b/document/src/main/java/com/yahoo/document/json/JsonSerializationHelper.java index 7b1042903ec..ed6bdc721a0 100644 --- a/document/src/main/java/com/yahoo/document/json/JsonSerializationHelper.java +++ b/document/src/main/java/com/yahoo/document/json/JsonSerializationHelper.java @@ -347,4 +347,5 @@ public class JsonSerializationHelper { wrapIOException(() -> generator.writeFieldName(field.getName())); } } + } diff --git a/document/src/main/java/com/yahoo/document/json/JsonWriter.java b/document/src/main/java/com/yahoo/document/json/JsonWriter.java index 7e82e830064..9cbadb65f10 100644 --- a/document/src/main/java/com/yahoo/document/json/JsonWriter.java +++ b/document/src/main/java/com/yahoo/document/json/JsonWriter.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.StreamReadConstraints; import com.yahoo.document.Document; import com.yahoo.document.DocumentId; +import com.yahoo.document.DocumentRemove; import com.yahoo.document.DocumentType; import com.yahoo.document.Field; import com.yahoo.document.annotation.AnnotationReference; @@ -263,6 +264,19 @@ public class JsonWriter implements DocumentWriter { // NOP, fetched from Document } + public void write(DocumentRemove documentRemove) { + try { + generator.writeStartObject(); + + serializeStringField(generator, new FieldBase("remove"), new StringFieldValue(documentRemove.getId().toString())); + + generator.writeEndObject(); + generator.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + /** * Utility method to easily serialize a single document. * diff --git a/document/src/main/java/com/yahoo/document/serialization/DocumentWriter.java b/document/src/main/java/com/yahoo/document/serialization/DocumentWriter.java index c84140c9ea0..10483d8609f 100644 --- a/document/src/main/java/com/yahoo/document/serialization/DocumentWriter.java +++ b/document/src/main/java/com/yahoo/document/serialization/DocumentWriter.java @@ -3,6 +3,7 @@ package com.yahoo.document.serialization; import com.yahoo.document.Document; import com.yahoo.document.DocumentId; +import com.yahoo.document.DocumentRemove; import com.yahoo.document.DocumentType; /** @@ -17,4 +18,6 @@ public interface DocumentWriter extends FieldWriter { void write(DocumentType type); + void write(DocumentRemove documentRemove); + } diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java index 17ab3890bcf..4cb836860be 100644 --- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java +++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java @@ -8,6 +8,7 @@ import com.yahoo.document.CollectionDataType; import com.yahoo.document.DataType; import com.yahoo.document.Document; import com.yahoo.document.DocumentId; +import com.yahoo.document.DocumentRemove; import com.yahoo.document.DocumentType; import com.yahoo.document.DocumentUpdate; import com.yahoo.document.Field; @@ -426,6 +427,10 @@ public class VespaDocumentSerializer6 extends BufferSerializer implements Docume putShort(null, (short) 0); // Used to hold the version. Is now always 0. } + public void write(DocumentRemove documentRemove) { + throw new UnsupportedOperationException("serializing remove not implemented"); + } + public void write(Annotation annotation) { buf.putInt(annotation.getType().getId()); //name hash diff --git a/messagebus/src/tests/configagent/CMakeLists.txt b/messagebus/src/tests/configagent/CMakeLists.txt index 9cc9eacbe1c..9b07222fc74 100644 --- a/messagebus/src/tests/configagent/CMakeLists.txt +++ b/messagebus/src/tests/configagent/CMakeLists.txt @@ -5,5 +5,6 @@ vespa_add_executable(messagebus_configagent_test_app TEST DEPENDS messagebus_messagebus-test messagebus + GTest::gtest ) vespa_add_test(NAME messagebus_configagent_test_app COMMAND messagebus_configagent_test_app) diff --git a/messagebus/src/tests/configagent/configagent.cpp b/messagebus/src/tests/configagent/configagent.cpp index f93bfd6c841..e8cab1e679a 100644 --- a/messagebus/src/tests/configagent/configagent.cpp +++ b/messagebus/src/tests/configagent/configagent.cpp @@ -1,109 +1,113 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/testapp.h> #include <vespa/messagebus/configagent.h> #include <vespa/messagebus/iconfighandler.h> #include <vespa/messagebus/routing/routingspec.h> #include <vespa/messagebus/config-messagebus.h> #include <vespa/config/print/fileconfigreader.hpp> +#include <vespa/vespalib/gtest/gtest.h> +#include <vespa/vespalib/testkit/test_path.h> using namespace mbus; using namespace messagebus; using namespace config; -class Test : public vespalib::TestApp, public IConfigHandler { -private: +class ConfigAgentTest : public testing::Test, public IConfigHandler { +protected: RoutingSpec _spec; + ConfigAgentTest(); + ~ConfigAgentTest() override; bool checkHalf(); bool checkFull(); - bool checkTables(uint32_t numTables); - -public: - ~Test() override; - int Main() override; + void checkTables(uint32_t numTables, bool& success); bool setupRouting(RoutingSpec spec) override; }; -Test::~Test() = default; +ConfigAgentTest::ConfigAgentTest() + : testing::Test(), + IConfigHandler(), + _spec() +{ +} -TEST_APPHOOK(Test); +ConfigAgentTest::~ConfigAgentTest() = default; bool -Test::setupRouting(RoutingSpec spec) +ConfigAgentTest::setupRouting(RoutingSpec spec) { _spec = std::move(spec); return true; } -bool -Test::checkTables(uint32_t numTables) +void +ConfigAgentTest::checkTables(uint32_t numTables, bool& success) { - if (!EXPECT_EQUAL(numTables, _spec.getNumTables())) return false; + ASSERT_EQ(numTables, _spec.getNumTables()); if (numTables > 0) { - if (!EXPECT_EQUAL("foo", _spec.getTable(0).getProtocol())) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(0).getNumHops())) return false; - if (!EXPECT_EQUAL("foo-h1", _spec.getTable(0).getHop(0).getName())) return false; - if (!EXPECT_EQUAL("foo-h1-sel", _spec.getTable(0).getHop(0).getSelector())) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(0).getHop(0).getNumRecipients())) return false; - if (!EXPECT_EQUAL("foo-h1-r1", _spec.getTable(0).getHop(0).getRecipient(0))) return false; - if (!EXPECT_EQUAL("foo-h1-r2", _spec.getTable(0).getHop(0).getRecipient(1))) return false; - if (!EXPECT_EQUAL(true, _spec.getTable(0).getHop(0).getIgnoreResult())) return false; - if (!EXPECT_EQUAL("foo-h2", _spec.getTable(0).getHop(1).getName())) return false; - if (!EXPECT_EQUAL("foo-h2-sel", _spec.getTable(0).getHop(1).getSelector())) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(0).getHop(1).getNumRecipients())) return false; - if (!EXPECT_EQUAL("foo-h2-r1", _spec.getTable(0).getHop(1).getRecipient(0))) return false; - if (!EXPECT_EQUAL("foo-h2-r2", _spec.getTable(0).getHop(1).getRecipient(1))) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(0).getNumRoutes())) return false; - if (!EXPECT_EQUAL("foo-r1", _spec.getTable(0).getRoute(0).getName())) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(0).getRoute(0).getNumHops())) return false; - if (!EXPECT_EQUAL("foo-h1", _spec.getTable(0).getRoute(0).getHop(0))) return false; - if (!EXPECT_EQUAL("foo-h2", _spec.getTable(0).getRoute(0).getHop(1))) return false; - if (!EXPECT_EQUAL("foo-r2", _spec.getTable(0).getRoute(1).getName())) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(0).getRoute(1).getNumHops())) return false; - if (!EXPECT_EQUAL("foo-h2", _spec.getTable(0).getRoute(1).getHop(0))) return false; - if (!EXPECT_EQUAL("foo-h1", _spec.getTable(0).getRoute(1).getHop(1))) return false; + ASSERT_EQ("foo", _spec.getTable(0).getProtocol()); + ASSERT_EQ(2u, _spec.getTable(0).getNumHops()); + ASSERT_EQ("foo-h1", _spec.getTable(0).getHop(0).getName()); + ASSERT_EQ("foo-h1-sel", _spec.getTable(0).getHop(0).getSelector()); + ASSERT_EQ(2u, _spec.getTable(0).getHop(0).getNumRecipients()); + ASSERT_EQ("foo-h1-r1", _spec.getTable(0).getHop(0).getRecipient(0)); + ASSERT_EQ("foo-h1-r2", _spec.getTable(0).getHop(0).getRecipient(1)); + ASSERT_EQ(true, _spec.getTable(0).getHop(0).getIgnoreResult()); + ASSERT_EQ("foo-h2", _spec.getTable(0).getHop(1).getName()); + ASSERT_EQ("foo-h2-sel", _spec.getTable(0).getHop(1).getSelector()); + ASSERT_EQ(2u, _spec.getTable(0).getHop(1).getNumRecipients()); + ASSERT_EQ("foo-h2-r1", _spec.getTable(0).getHop(1).getRecipient(0)); + ASSERT_EQ("foo-h2-r2", _spec.getTable(0).getHop(1).getRecipient(1)); + ASSERT_EQ(2u, _spec.getTable(0).getNumRoutes()); + ASSERT_EQ("foo-r1", _spec.getTable(0).getRoute(0).getName()); + ASSERT_EQ(2u, _spec.getTable(0).getRoute(0).getNumHops()); + ASSERT_EQ("foo-h1", _spec.getTable(0).getRoute(0).getHop(0)); + ASSERT_EQ("foo-h2", _spec.getTable(0).getRoute(0).getHop(1)); + ASSERT_EQ("foo-r2", _spec.getTable(0).getRoute(1).getName()); + ASSERT_EQ(2u, _spec.getTable(0).getRoute(1).getNumHops()); + ASSERT_EQ("foo-h2", _spec.getTable(0).getRoute(1).getHop(0)); + ASSERT_EQ("foo-h1", _spec.getTable(0).getRoute(1).getHop(1)); } if (numTables > 1) { - if (!EXPECT_EQUAL("bar", _spec.getTable(1).getProtocol())) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(1).getNumHops())) return false; - if (!EXPECT_EQUAL("bar-h1", _spec.getTable(1).getHop(0).getName())) return false; - if (!EXPECT_EQUAL("bar-h1-sel", _spec.getTable(1).getHop(0).getSelector())) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(1).getHop(0).getNumRecipients())) return false; - if (!EXPECT_EQUAL("bar-h1-r1", _spec.getTable(1).getHop(0).getRecipient(0))) return false; - if (!EXPECT_EQUAL("bar-h1-r2", _spec.getTable(1).getHop(0).getRecipient(1))) return false; - if (!EXPECT_EQUAL("bar-h2", _spec.getTable(1).getHop(1).getName())) return false; - if (!EXPECT_EQUAL("bar-h2-sel", _spec.getTable(1).getHop(1).getSelector())) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(1).getHop(1).getNumRecipients())) return false; - if (!EXPECT_EQUAL("bar-h2-r1", _spec.getTable(1).getHop(1).getRecipient(0))) return false; - if (!EXPECT_EQUAL("bar-h2-r2", _spec.getTable(1).getHop(1).getRecipient(1))) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(1).getNumRoutes())) return false; - if (!EXPECT_EQUAL("bar-r1", _spec.getTable(1).getRoute(0).getName())) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(1).getRoute(0).getNumHops())) return false; - if (!EXPECT_EQUAL("bar-h1", _spec.getTable(1).getRoute(0).getHop(0))) return false; - if (!EXPECT_EQUAL("bar-h2", _spec.getTable(1).getRoute(0).getHop(1))) return false; - if (!EXPECT_EQUAL("bar-r2", _spec.getTable(1).getRoute(1).getName())) return false; - if (!EXPECT_EQUAL(2u, _spec.getTable(1).getRoute(1).getNumHops())) return false; - if (!EXPECT_EQUAL("bar-h2", _spec.getTable(1).getRoute(1).getHop(0))) return false; - if (!EXPECT_EQUAL("bar-h1", _spec.getTable(1).getRoute(1).getHop(1))) return false; + ASSERT_EQ("bar", _spec.getTable(1).getProtocol()); + ASSERT_EQ(2u, _spec.getTable(1).getNumHops()); + ASSERT_EQ("bar-h1", _spec.getTable(1).getHop(0).getName()); + ASSERT_EQ("bar-h1-sel", _spec.getTable(1).getHop(0).getSelector()); + ASSERT_EQ(2u, _spec.getTable(1).getHop(0).getNumRecipients()); + ASSERT_EQ("bar-h1-r1", _spec.getTable(1).getHop(0).getRecipient(0)); + ASSERT_EQ("bar-h1-r2", _spec.getTable(1).getHop(0).getRecipient(1)); + ASSERT_EQ("bar-h2", _spec.getTable(1).getHop(1).getName()); + ASSERT_EQ("bar-h2-sel", _spec.getTable(1).getHop(1).getSelector()); + ASSERT_EQ(2u, _spec.getTable(1).getHop(1).getNumRecipients()); + ASSERT_EQ("bar-h2-r1", _spec.getTable(1).getHop(1).getRecipient(0)); + ASSERT_EQ("bar-h2-r2", _spec.getTable(1).getHop(1).getRecipient(1)); + ASSERT_EQ(2u, _spec.getTable(1).getNumRoutes()); + ASSERT_EQ("bar-r1", _spec.getTable(1).getRoute(0).getName()); + ASSERT_EQ(2u, _spec.getTable(1).getRoute(0).getNumHops()); + ASSERT_EQ("bar-h1", _spec.getTable(1).getRoute(0).getHop(0)); + ASSERT_EQ("bar-h2", _spec.getTable(1).getRoute(0).getHop(1)); + ASSERT_EQ("bar-r2", _spec.getTable(1).getRoute(1).getName()); + ASSERT_EQ(2u, _spec.getTable(1).getRoute(1).getNumHops()); + ASSERT_EQ("bar-h2", _spec.getTable(1).getRoute(1).getHop(0)); + ASSERT_EQ("bar-h1", _spec.getTable(1).getRoute(1).getHop(1)); } - return true; + success = true; } bool -Test::checkHalf() +ConfigAgentTest::checkHalf() { - return _spec.getNumTables() == 1 && EXPECT_TRUE(checkTables(1)); + bool success = false; + return _spec.getNumTables() == 1 && (checkTables(1, success), success); } bool -Test::checkFull() +ConfigAgentTest::checkFull() { - return _spec.getNumTables() == 2 && EXPECT_TRUE(checkTables(2)); + bool success = false; + return _spec.getNumTables() == 2 && (checkTables(2, success), success); } -int -Test::Main() +TEST_F(ConfigAgentTest, test_config_agent) { - TEST_INIT("configagent_test"); EXPECT_TRUE(!checkHalf()); EXPECT_TRUE(!checkFull()); ConfigAgent agent(*this); @@ -118,5 +122,6 @@ Test::Main() agent.configure(FileConfigReader<MessagebusConfig>(TEST_PATH("full.cfg")).read()); EXPECT_TRUE(checkFull()); EXPECT_TRUE(!checkHalf()); - TEST_DONE(); } + +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/messagebus/src/tests/messagebus/CMakeLists.txt b/messagebus/src/tests/messagebus/CMakeLists.txt index 3f79e2ed851..f05141ca28f 100644 --- a/messagebus/src/tests/messagebus/CMakeLists.txt +++ b/messagebus/src/tests/messagebus/CMakeLists.txt @@ -5,5 +5,6 @@ vespa_add_executable(messagebus_messagebus_test_app TEST DEPENDS messagebus_messagebus-test messagebus + GTest::gtest ) vespa_add_test(NAME messagebus_messagebus_test_app COMMAND messagebus_messagebus_test_app) diff --git a/messagebus/src/tests/messagebus/messagebus.cpp b/messagebus/src/tests/messagebus/messagebus.cpp index 5c1bdc54f00..e4d90a3c198 100644 --- a/messagebus/src/tests/messagebus/messagebus.cpp +++ b/messagebus/src/tests/messagebus/messagebus.cpp @@ -11,8 +11,8 @@ #include <vespa/messagebus/testlib/simpleprotocol.h> #include <vespa/messagebus/testlib/slobrok.h> #include <vespa/messagebus/testlib/testserver.h> -#include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/stringfmt.h> +#include <vespa/vespalib/gtest/gtest.h> #include <thread> using namespace mbus; @@ -98,8 +98,8 @@ struct Search : public Server { //----------------------------------------------------------------------------- -class Test : public vespalib::TestApp { -private: +class MessageBusTest : public testing::Test { +protected: Slobrok::UP slobrok; Client::UP client; DocProc::UP dp0; @@ -112,44 +112,21 @@ private: std::vector<DocProc*> dpVec; std::vector<Search*> searchVec; -public: - Test(); - ~Test(); - int Main() override; - void testSendToCol(); - void testDirectHop(); - void testDirectRoute(); - void testRoutingPolicyCache(); - -private: - void setup(); - void teardown(); + MessageBusTest(); + ~MessageBusTest(); + void SetUp() override; + void TearDown() override; void assertSrc(Client& src); void assertItr(DocProc& itr); void assertDst(Search& dst); }; -TEST_APPHOOK(Test); - -Test::Test() = default; -Test::~Test() = default; - -int -Test::Main() -{ - TEST_INIT("messagebus_test"); - - testSendToCol(); TEST_FLUSH(); - testDirectHop(); TEST_FLUSH(); - testDirectRoute(); TEST_FLUSH(); - testRoutingPolicyCache(); TEST_FLUSH(); - - TEST_DONE(); -} +MessageBusTest::MessageBusTest() = default; +MessageBusTest::~MessageBusTest() = default; void -Test::setup() +MessageBusTest::SetUp() { slobrok.reset(new Slobrok()); client.reset(new Client(*slobrok)); @@ -188,7 +165,8 @@ Test::setup() ASSERT_TRUE(dp2->server.waitSlobrok("search/r.1/c.1/session")); } -void Test::teardown() +void +MessageBusTest::TearDown() { dpVec.clear(); searchVec.clear(); @@ -203,10 +181,8 @@ void Test::teardown() slobrok.reset(); } -void -Test::testSendToCol() +TEST_F(MessageBusTest, test_send_to_col) { - setup(); ASSERT_TRUE(SimpleMessage("msg").getHash() % 2 == 0); for (uint32_t i = 0; i < 150; ++i) { Message::UP msg(new SimpleMessage("msg")); @@ -244,13 +220,10 @@ Test::testSendToCol() ASSERT_TRUE(reply->isReply()); EXPECT_TRUE(static_cast<Reply&>(*reply).getNumErrors() == 0); } - teardown(); } -void -Test::testDirectHop() +TEST_F(MessageBusTest, test_direct_hop) { - setup(); for (int row = 0; row < 2; row++) { for (int col = 0; col < 2; col++) { Search* dst = searchVec[row * 2 + col]; @@ -260,25 +233,22 @@ Test::testDirectHop() Message::UP(new SimpleMessage("empty")), Route().addHop(vespalib::make_string("search/r.%d/c.%d/session", row, col))) .isAccepted()); - assertDst(*dst); - assertSrc(*client); + ASSERT_NO_FATAL_FAILURE(assertDst(*dst)); + ASSERT_NO_FATAL_FAILURE(assertSrc(*client)); // Send using address. ASSERT_TRUE(client->session->send( Message::UP(new SimpleMessage("empty")), Route().addHop(Hop(dst->session->getConnectionSpec().c_str()))) .isAccepted()); - assertDst(*dst); - assertSrc(*client); + ASSERT_NO_FATAL_FAILURE(assertDst(*dst)); + ASSERT_NO_FATAL_FAILURE(assertSrc(*client)); } } - teardown(); } -void -Test::testDirectRoute() +TEST_F(MessageBusTest, test_direct_route) { - setup(); ASSERT_TRUE(client->session->send( Message::UP(new SimpleMessage("empty")), Route() @@ -290,26 +260,24 @@ Test::testDirectRoute() .addHop(Hop(dp2->session->getConnectionSpec())) .addHop(Hop("search/r.0/c.0/session"))) .isAccepted()); - assertItr(*dp0); - assertItr(*dp0); - assertItr(*dp1); - assertItr(*dp1); - assertItr(*dp2); - assertItr(*dp2); - assertDst(*search00); - assertItr(*dp2); - assertItr(*dp2); - assertItr(*dp1); - assertItr(*dp1); - assertItr(*dp0); - assertItr(*dp0); - assertSrc(*client); - - teardown(); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp0)); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp0)); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp1)); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp1)); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp2)); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp2)); + ASSERT_NO_FATAL_FAILURE(assertDst(*search00)); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp2)); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp2)); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp1)); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp1)); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp0)); + ASSERT_NO_FATAL_FAILURE(assertItr(*dp0)); + ASSERT_NO_FATAL_FAILURE(assertSrc(*client)); } void -Test::assertDst(Search& dst) +MessageBusTest::assertDst(Search& dst) { ASSERT_TRUE(dst.waitQueueSize(1)); Routable::UP msg = dst.queue.dequeue(); @@ -318,7 +286,7 @@ Test::assertDst(Search& dst) } void -Test::assertItr(DocProc& itr) +MessageBusTest::assertItr(DocProc& itr) { ASSERT_TRUE(itr.waitQueueSize(1)); Routable::UP msg = itr.queue.dequeue(); @@ -327,17 +295,15 @@ Test::assertItr(DocProc& itr) } void -Test::assertSrc(Client& src) +MessageBusTest::assertSrc(Client& src) { ASSERT_TRUE(src.waitQueueSize(1)); Routable::UP msg = src.queue.dequeue(); ASSERT_TRUE(msg); } -void -Test::testRoutingPolicyCache() +TEST_F(MessageBusTest, test_routing_policy_cache) { - setup(); MessageBus &bus = client->server.mb; IRoutingPolicy::SP all = bus.getRoutingPolicy(SimpleProtocol::NAME, "All", ""); @@ -354,6 +320,6 @@ Test::testRoutingPolicyCache() IRoutingPolicy::SP refArg = bus.getRoutingPolicy(SimpleProtocol::NAME, "All", "Arg"); ASSERT_TRUE(refArg.get() != NULL); ASSERT_TRUE(allArg.get() == refArg.get()); - - teardown(); } + +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespaclient-java/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java b/vespaclient-java/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java index b4ca98f316f..b41bb29376b 100644 --- a/vespaclient-java/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java +++ b/vespaclient-java/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java @@ -185,21 +185,34 @@ public class SimpleFeeder implements ReplyHandler { } } public void send(FeedOperation op) { - if (op.getType() == FeedOperation.Type.DOCUMENT) { - if (!isFirst) { - try { - outputStream.write(','); - outputStream.write('\n'); - } catch (IOException e) { - failure.set(e); - } - } else { - isFirst = false; + switch (op.getType()) { + case DOCUMENT -> { + addCommaAndNewline(); + writer.write(op.getDocumentPut().getDocument()); } - writer.write(op.getDocumentPut().getDocument()); + case REMOVE -> { + addCommaAndNewline(); + writer.write(op.getDocumentRemove()); + } + default -> { /* TODO: No more operations supported yet */ } } numReplies.incrementAndGet(); } + + private void addCommaAndNewline() { + if (! isFirst) { + try { + outputStream.write(','); + outputStream.write('\n'); + } catch (IOException e) { + failure.set(e); + } + } + else { + isFirst = false; + } + } + public void close() throws Exception { outputStream.write('\n'); outputStream.write(']'); diff --git a/vespaclient-java/src/test/java/com/yahoo/vespa/feed/perf/SimpleFeederTest.java b/vespaclient-java/src/test/java/com/yahoo/vespa/feed/perf/SimpleFeederTest.java index 582148e8eaa..28859d0e7c4 100644 --- a/vespaclient-java/src/test/java/com/yahoo/vespa/feed/perf/SimpleFeederTest.java +++ b/vespaclient-java/src/test/java/com/yahoo/vespa/feed/perf/SimpleFeederTest.java @@ -87,8 +87,13 @@ public class SimpleFeederTest { "", "(.+\n)+" + "\\s*\\d+,\\s*3,.+\n"); - assertEquals(58, dump.size()); - assertEquals("[\n{\"id\":\"id:simple:simple::0\",\"fields\":{\"my_str\":\"foo\"}}\n]", dump.toString()); + assertEquals(93, dump.size()); + assertEquals(""" + [ + {"id":"id:simple:simple::0","fields":{"my_str":"foo"}}, + {"remove":"id:simple:simple::2"} + ]""", + dump.toString()); } @Test @@ -116,8 +121,14 @@ public class SimpleFeederTest { "", "(.+\n)+" + "\\s*\\d+,\\s*3,.+\n"); - assertEquals(115, dump.size()); - assertEquals("[\n{\"id\":\"id:simple:simple::0\",\"fields\":{\"my_str\":\"foo\"}},\n {\"id\":\"id:simple:simple::1\",\"fields\":{\"my_str\":\"bar\"}}\n]", dump.toString()); + assertEquals(150, dump.size()); + assertEquals(""" + [ + {"id":"id:simple:simple::0","fields":{"my_str":"foo"}}, + {"id":"id:simple:simple::1","fields":{"my_str":"bar"}}, + {"remove":"id:simple:simple::2"} + ]""", + dump.toString()); assertFeed(dump.toString(), new MessageHandler() { @Override @@ -129,7 +140,7 @@ public class SimpleFeederTest { }, "", "(.+\n)+" + - "\\s*\\d+,\\s*2,.+\n"); + "\\s*\\d+,\\s*3,.+\n"); } @Test |