diff options
17 files changed, 337 insertions, 343 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/advancedrouting/CMakeLists.txt b/messagebus/src/tests/advancedrouting/CMakeLists.txt index dc4013b833f..ca2d3e4bba0 100644 --- a/messagebus/src/tests/advancedrouting/CMakeLists.txt +++ b/messagebus/src/tests/advancedrouting/CMakeLists.txt @@ -5,5 +5,6 @@ vespa_add_executable(messagebus_advancedrouting_test_app TEST DEPENDS messagebus_messagebus-test messagebus + GTest::gtest ) vespa_add_test(NAME messagebus_advancedrouting_test_app COMMAND messagebus_advancedrouting_test_app) diff --git a/messagebus/src/tests/advancedrouting/advancedrouting.cpp b/messagebus/src/tests/advancedrouting/advancedrouting.cpp index ce4a13d435a..4415674986e 100644 --- a/messagebus/src/tests/advancedrouting/advancedrouting.cpp +++ b/messagebus/src/tests/advancedrouting/advancedrouting.cpp @@ -5,14 +5,16 @@ #include <vespa/messagebus/testlib/simplemessage.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/messagebus/emptyreply.h> #include <vespa/messagebus/errorcode.h> #include <vespa/messagebus/routing/retrytransienterrorspolicy.h> +#include <vespa/vespalib/gtest/gtest.h> using namespace mbus; +namespace { + class TestData { public: Slobrok _slobrok; @@ -34,38 +36,27 @@ public: bool start(); }; -class Test : public vespalib::TestApp { -private: - Message::UP createMessage(const string &msg); - bool testTrace(const std::vector<string> &expected, const Trace &trace); - -public: - int Main() override; - void testAdvanced(TestData &data); -}; - -TEST_APPHOOK(Test); - -TestData::~TestData() = default; -TestData::TestData() : - _slobrok(), - _retryPolicy(std::make_shared<RetryTransientErrorsPolicy>()), - _srcServer(MessageBusParams().setRetryPolicy(_retryPolicy).addProtocol(std::make_shared<SimpleProtocol>()), - RPCNetworkParams(_slobrok.config())), - _srcSession(), - _srcHandler(), - _dstServer(MessageBusParams().addProtocol(std::make_shared<SimpleProtocol>()), - RPCNetworkParams(_slobrok.config()).setIdentity(Identity("dst"))), - _fooSession(), - _fooHandler(), - _barSession(), - _barHandler(), - _bazSession(), - _bazHandler() +TestData::TestData() + : _slobrok(), + _retryPolicy(std::make_shared<RetryTransientErrorsPolicy>()), + _srcServer(MessageBusParams().setRetryPolicy(_retryPolicy).addProtocol(std::make_shared<SimpleProtocol>()), + RPCNetworkParams(_slobrok.config())), + _srcSession(), + _srcHandler(), + _dstServer(MessageBusParams().addProtocol(std::make_shared<SimpleProtocol>()), + RPCNetworkParams(_slobrok.config()).setIdentity(Identity("dst"))), + _fooSession(), + _fooHandler(), + _barSession(), + _barHandler(), + _bazSession(), + _bazHandler() { _retryPolicy->setBaseDelay(0); } +TestData::~TestData() = default; + bool TestData::start() { @@ -91,30 +82,21 @@ TestData::start() return true; } -Message::UP -Test::createMessage(const string &msg) +std::unique_ptr<Message> +createMessage(const string &msg) { auto ret = std::make_unique<SimpleMessage>(msg); ret->getTrace().setLevel(9); return ret; } -int -Test::Main() -{ - TEST_INIT("routing_test"); +} +TEST(AdvancedRoutingTest, test_advanced) +{ TestData data; ASSERT_TRUE(data.start()); - testAdvanced(data); TEST_FLUSH(); - - TEST_DONE(); -} - -void -Test::testAdvanced(TestData &data) -{ const duration TIMEOUT = 60s; IProtocol::SP protocol(new SimpleProtocol()); auto &simple = dynamic_cast<SimpleProtocol&>(*protocol); @@ -174,7 +156,9 @@ Test::testAdvanced(TestData &data) reply = data._srcHandler.getReply(); ASSERT_TRUE(reply); printf("%s", reply->getTrace().toString().c_str()); - EXPECT_EQUAL(2u, reply->getNumErrors()); - EXPECT_EQUAL((uint32_t)ErrorCode::FATAL_ERROR, reply->getError(0).getCode()); - EXPECT_EQUAL((uint32_t)ErrorCode::NO_ADDRESS_FOR_SERVICE, reply->getError(1).getCode()); + EXPECT_EQ(2u, reply->getNumErrors()); + EXPECT_EQ((uint32_t)ErrorCode::FATAL_ERROR, reply->getError(0).getCode()); + EXPECT_EQ((uint32_t)ErrorCode::NO_ADDRESS_FOR_SERVICE, reply->getError(1).getCode()); } + +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/messagebus/src/tests/choke/CMakeLists.txt b/messagebus/src/tests/choke/CMakeLists.txt index b4db862f717..c87c51f8c82 100644 --- a/messagebus/src/tests/choke/CMakeLists.txt +++ b/messagebus/src/tests/choke/CMakeLists.txt @@ -5,5 +5,6 @@ vespa_add_executable(messagebus_choke_test_app TEST DEPENDS messagebus_messagebus-test messagebus + GTest::gtest ) vespa_add_test(NAME messagebus_choke_test_app NO_VALGRIND COMMAND messagebus_choke_test_app) diff --git a/messagebus/src/tests/choke/choke.cpp b/messagebus/src/tests/choke/choke.cpp index 313aace8fd4..9c25fc64cd1 100644 --- a/messagebus/src/tests/choke/choke.cpp +++ b/messagebus/src/tests/choke/choke.cpp @@ -7,7 +7,7 @@ #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/gtest/gtest.h> using namespace mbus; @@ -17,6 +17,8 @@ using namespace mbus; // //////////////////////////////////////////////////////////////////////////////// +namespace { + class TestData { public: Slobrok _slobrok; @@ -33,32 +35,20 @@ public: bool start(); }; -class Test : public vespalib::TestApp { -private: - Message::UP createMessage(const string &msg); - -public: - int Main() override; - void testMaxCount(TestData &data); - void testMaxSize(TestData &data); -}; - -TEST_APPHOOK(Test); - -TestData::TestData() : - _slobrok(), - _srcServer(MessageBusParams() - .setRetryPolicy(IRetryPolicy::SP()) - .addProtocol(std::make_shared<SimpleProtocol>()), - RPCNetworkParams(_slobrok.config())), - _srcSession(), - _srcHandler(), - _dstServer(MessageBusParams() - .addProtocol(std::make_shared<SimpleProtocol>()), - RPCNetworkParams(_slobrok.config()) - .setIdentity(Identity("dst"))), - _dstSession(), - _dstHandler() +TestData::TestData() + : _slobrok(), + _srcServer(MessageBusParams() + .setRetryPolicy(IRetryPolicy::SP()) + .addProtocol(std::make_shared<SimpleProtocol>()), + RPCNetworkParams(_slobrok.config())), + _srcSession(), + _srcHandler(), + _dstServer(MessageBusParams() + .addProtocol(std::make_shared<SimpleProtocol>()), + RPCNetworkParams(_slobrok.config()) + .setIdentity(Identity("dst"))), + _dstSession(), + _dstHandler() { // empty } @@ -86,26 +76,41 @@ TestData::start() return true; } -Message::UP -Test::createMessage(const string &msg) +std::unique_ptr<Message> +createMessage(const string &msg) { Message::UP ret(new SimpleMessage(msg)); ret->getTrace().setLevel(9); return ret; } -int -Test::Main() -{ - TEST_INIT("choke_test"); +} + +class ChokeTest : public testing::Test { +protected: + static std::shared_ptr<TestData> _data; + ChokeTest(); + ~ChokeTest() override; + static void SetUpTestSuite(); + static void TearDownTestSuite(); +}; - TestData data; - ASSERT_TRUE(data.start()); +std::shared_ptr<TestData> ChokeTest::_data; - testMaxCount(data); TEST_FLUSH(); - testMaxSize(data); TEST_FLUSH(); +ChokeTest::ChokeTest() = default; +ChokeTest::~ChokeTest() = default; - TEST_DONE(); +void +ChokeTest::SetUpTestSuite() +{ + _data = std::make_shared<TestData>(); + ASSERT_TRUE(_data->start()); +} + +void +ChokeTest::TearDownTestSuite() +{ + _data.reset(); } static const duration TIMEOUT = 120s; @@ -116,17 +121,17 @@ static const duration TIMEOUT = 120s; // //////////////////////////////////////////////////////////////////////////////// -void -Test::testMaxCount(TestData &data) +TEST_F(ChokeTest, test_max_count) { + auto& data = *_data; uint32_t max = 10; data._dstServer.mb.setMaxPendingCount(max); std::vector<Message*> lst; for (uint32_t i = 0; i < max * 2; ++i) { if (i < max) { - EXPECT_EQUAL(i, data._dstServer.mb.getPendingCount()); + EXPECT_EQ(i, data._dstServer.mb.getPendingCount()); } else { - EXPECT_EQUAL(max, data._dstServer.mb.getPendingCount()); + EXPECT_EQ(max, data._dstServer.mb.getPendingCount()); } EXPECT_TRUE(data._srcSession->send(createMessage("msg"), Route::parse("dst/session")).isAccepted()); if (i < max) { @@ -136,8 +141,8 @@ Test::testMaxCount(TestData &data) } else { Reply::UP reply = data._srcHandler.getReply(); ASSERT_TRUE(reply); - EXPECT_EQUAL(1u, reply->getNumErrors()); - EXPECT_EQUAL((uint32_t)ErrorCode::SESSION_BUSY, reply->getError(0).getCode()); + EXPECT_EQ(1u, reply->getNumErrors()); + EXPECT_EQ((uint32_t)ErrorCode::SESSION_BUSY, reply->getError(0).getCode()); } } for (uint32_t i = 0; i < 5; ++i) { @@ -157,7 +162,7 @@ Test::testMaxCount(TestData &data) lst.push_back(msg.release()); } while (!lst.empty()) { - EXPECT_EQUAL(lst.size(), data._dstServer.mb.getPendingCount()); + EXPECT_EQ(lst.size(), data._dstServer.mb.getPendingCount()); Message::UP msg(lst[0]); lst.erase(lst.begin()); data._dstSession->acknowledge(std::move(msg)); @@ -166,21 +171,21 @@ Test::testMaxCount(TestData &data) ASSERT_TRUE(reply); EXPECT_TRUE(!reply->hasErrors()); } - EXPECT_EQUAL(0u, data._dstServer.mb.getPendingCount()); + EXPECT_EQ(0u, data._dstServer.mb.getPendingCount()); } -void -Test::testMaxSize(TestData &data) +TEST_F(ChokeTest, test_max_size) { + auto& data = *_data; uint32_t size = createMessage("msg")->getApproxSize(); uint32_t max = size * 10; data._dstServer.mb.setMaxPendingSize(max); std::vector<Message*> lst; for (uint32_t i = 0; i < max * 2; i += size) { if (i < max) { - EXPECT_EQUAL(i, data._dstServer.mb.getPendingSize()); + EXPECT_EQ(i, data._dstServer.mb.getPendingSize()); } else { - EXPECT_EQUAL(max, data._dstServer.mb.getPendingSize()); + EXPECT_EQ(max, data._dstServer.mb.getPendingSize()); } EXPECT_TRUE(data._srcSession->send(createMessage("msg"), Route::parse("dst/session")).isAccepted()); if (i < max) { @@ -190,8 +195,8 @@ Test::testMaxSize(TestData &data) } else { Reply::UP reply = data._srcHandler.getReply(); ASSERT_TRUE(reply); - EXPECT_EQUAL(1u, reply->getNumErrors()); - EXPECT_EQUAL((uint32_t)ErrorCode::SESSION_BUSY, reply->getError(0).getCode()); + EXPECT_EQ(1u, reply->getNumErrors()); + EXPECT_EQ((uint32_t)ErrorCode::SESSION_BUSY, reply->getError(0).getCode()); } } for (uint32_t i = 0; i < 5; ++i) { @@ -211,7 +216,7 @@ Test::testMaxSize(TestData &data) lst.push_back(msg.release()); } while (!lst.empty()) { - EXPECT_EQUAL(size * lst.size(), data._dstServer.mb.getPendingSize()); + EXPECT_EQ(size * lst.size(), data._dstServer.mb.getPendingSize()); Message::UP msg(lst[0]); lst.erase(lst.begin()); data._dstSession->acknowledge(std::move(msg)); @@ -220,5 +225,7 @@ Test::testMaxSize(TestData &data) ASSERT_TRUE(reply); EXPECT_TRUE(!reply->hasErrors()); } - EXPECT_EQUAL(0u, data._dstServer.mb.getPendingSize()); + EXPECT_EQ(0u, data._dstServer.mb.getPendingSize()); } + +GTEST_MAIN_RUN_ALL_TESTS() 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/messagebus/src/tests/resender/CMakeLists.txt b/messagebus/src/tests/resender/CMakeLists.txt index 2d0e5dbbb61..c364806b2dd 100644 --- a/messagebus/src/tests/resender/CMakeLists.txt +++ b/messagebus/src/tests/resender/CMakeLists.txt @@ -5,5 +5,6 @@ vespa_add_executable(messagebus_resender_test_app TEST DEPENDS messagebus_messagebus-test messagebus + GTest::gtest ) vespa_add_test(NAME messagebus_resender_test_app COMMAND messagebus_resender_test_app) diff --git a/messagebus/src/tests/resender/resender.cpp b/messagebus/src/tests/resender/resender.cpp index b9c75c36dd0..e61d3704909 100644 --- a/messagebus/src/tests/resender/resender.cpp +++ b/messagebus/src/tests/resender/resender.cpp @@ -9,26 +9,11 @@ #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/gtest/gtest.h> using namespace mbus; -//////////////////////////////////////////////////////////////////////////////// -// -// Utilities -// -//////////////////////////////////////////////////////////////////////////////// - -class StringList : public std::vector<string> { -public: - StringList &add(const string &str); -}; - -StringList & -StringList::add(const string &str) -{ - std::vector<string>::push_back(str); return *this; -} +namespace { static const duration GET_MESSAGE_TIMEOUT = 60s; @@ -55,35 +40,17 @@ public: bool start(); }; -class Test : public vespalib::TestApp { -private: - Message::UP createMessage(const string &msg); - void replyFromDestination(TestData &data, Message::UP msg, uint32_t errorCode, double retryDelay); - -public: - int Main() override; - void testRetryTag(TestData &data); - void testRetryEnabledTag(TestData &data); - void testTransientError(TestData &data); - void testFatalError(TestData &data); - void testDisableRetry(TestData &data); - void testRetryDelay(TestData &data); - void testRequestRetryDelay(TestData &data); -}; - -TEST_APPHOOK(Test); - -TestData::TestData() : - _slobrok(), - _retryPolicy(new RetryTransientErrorsPolicy()), - _srcServer(MessageBusParams().setRetryPolicy(_retryPolicy).addProtocol(std::make_shared<SimpleProtocol>()), - RPCNetworkParams(_slobrok.config())), - _srcSession(), - _srcHandler(), - _dstServer(MessageBusParams().addProtocol(std::make_shared<SimpleProtocol>()), - RPCNetworkParams(_slobrok.config()).setIdentity(Identity("dst"))), - _dstSession(), - _dstHandler() +TestData::TestData() + : _slobrok(), + _retryPolicy(new RetryTransientErrorsPolicy()), + _srcServer(MessageBusParams().setRetryPolicy(_retryPolicy).addProtocol(std::make_shared<SimpleProtocol>()), + RPCNetworkParams(_slobrok.config())), + _srcSession(), + _srcHandler(), + _dstServer(MessageBusParams().addProtocol(std::make_shared<SimpleProtocol>()), + RPCNetworkParams(_slobrok.config()).setIdentity(Identity("dst"))), + _dstSession(), + _dstHandler() { } TestData::~TestData() = default; @@ -105,35 +72,16 @@ TestData::start() return true; } -Message::UP -Test::createMessage(const string &msg) +std::unique_ptr<Message> +createMessage(const string &msg) { Message::UP ret(new SimpleMessage(msg)); ret->getTrace().setLevel(9); return ret; } -int -Test::Main() -{ - TEST_INIT("resender_test"); - - TestData data; - ASSERT_TRUE(data.start()); - - testRetryTag(data); TEST_FLUSH(); - testRetryEnabledTag(data); TEST_FLUSH(); - testTransientError(data); TEST_FLUSH(); - testFatalError(data); TEST_FLUSH(); - testDisableRetry(data); TEST_FLUSH(); - testRetryDelay(data); TEST_FLUSH(); - testRequestRetryDelay(data); TEST_FLUSH(); - - TEST_DONE(); -} - void -Test::replyFromDestination(TestData &data, Message::UP msg, uint32_t errorCode, double retryDelay) +replyFromDestination(TestData &data, Message::UP msg, uint32_t errorCode, double retryDelay) { Reply::UP reply(new EmptyReply()); reply->swapState(*msg); @@ -144,22 +92,51 @@ Test::replyFromDestination(TestData &data, Message::UP msg, uint32_t errorCode, data._dstSession->reply(std::move(reply)); } +} + +class ResenderTest : public testing::Test { +protected: + static std::shared_ptr<TestData> _data; + ResenderTest(); + ~ResenderTest() override; + static void SetUpTestSuite(); + static void TearDownTestSuite(); +}; + +std::shared_ptr<TestData> ResenderTest::_data; + +ResenderTest::ResenderTest() = default; +ResenderTest::~ResenderTest() = default; + +void +ResenderTest::SetUpTestSuite() +{ + _data = std::make_shared<TestData>(); + ASSERT_TRUE(_data->start()); +} + +void +ResenderTest::TearDownTestSuite() +{ + _data.reset(); +} + //////////////////////////////////////////////////////////////////////////////// // // Tests // //////////////////////////////////////////////////////////////////////////////// -void -Test::testRetryTag(TestData &data) +TEST_F(ResenderTest, test_retry_tag) { + auto& data = *_data; data._retryPolicy->setEnabled(true); EXPECT_TRUE(data._srcSession->send(createMessage("msg"), Route::parse("dst/session")).isAccepted()); Message::UP msg = data._dstHandler.getMessage(GET_MESSAGE_TIMEOUT); ASSERT_TRUE(msg); for (uint32_t i = 0; i < 5; ++i) { - EXPECT_EQUAL(i, msg->getRetry()); - EXPECT_EQUAL(true, msg->getRetryEnabled()); + EXPECT_EQ(i, msg->getRetry()); + EXPECT_EQ(true, msg->getRetryEnabled()); replyFromDestination(data, std::move(msg), ErrorCode::APP_TRANSIENT_ERROR, 0); msg = data._dstHandler.getMessage(GET_MESSAGE_TIMEOUT); ASSERT_TRUE(msg); @@ -173,16 +150,16 @@ Test::testRetryTag(TestData &data) printf("%s", reply->getTrace().toString().c_str()); } -void -Test::testRetryEnabledTag(TestData &data) +TEST_F(ResenderTest, test_retry_enabled_tag) { + auto& data = *_data; data._retryPolicy->setEnabled(true); Message::UP msg = createMessage("msg"); msg->setRetryEnabled(false); EXPECT_TRUE(data._srcSession->send(std::move(msg), Route::parse("dst/session")).isAccepted()); msg = data._dstHandler.getMessage(GET_MESSAGE_TIMEOUT); ASSERT_TRUE(msg); - EXPECT_EQUAL(false, msg->getRetryEnabled()); + EXPECT_EQ(false, msg->getRetryEnabled()); replyFromDestination(data, std::move(msg), ErrorCode::APP_TRANSIENT_ERROR, 0); Reply::UP reply = data._srcHandler.getReply(); ASSERT_TRUE(reply); @@ -192,9 +169,9 @@ Test::testRetryEnabledTag(TestData &data) printf("%s", reply->getTrace().toString().c_str()); } -void -Test::testTransientError(TestData &data) +TEST_F(ResenderTest, test_transient_error) { + auto& data = *_data; data._retryPolicy->setEnabled(true); EXPECT_TRUE(data._srcSession->send(createMessage("msg"), Route::parse("dst/session")).isAccepted()); Message::UP msg = data._dstHandler.getMessage(GET_MESSAGE_TIMEOUT); @@ -211,9 +188,9 @@ Test::testTransientError(TestData &data) printf("%s", reply->getTrace().toString().c_str()); } -void -Test::testFatalError(TestData &data) +TEST_F(ResenderTest, test_fatal_error) { + auto& data = *_data; data._retryPolicy->setEnabled(true); EXPECT_TRUE(data._srcSession->send(createMessage("msg"), Route::parse("dst/session")).isAccepted()); Message::UP msg = data._dstHandler.getMessage(GET_MESSAGE_TIMEOUT); @@ -227,9 +204,9 @@ Test::testFatalError(TestData &data) printf("%s", reply->getTrace().toString().c_str()); } -void -Test::testDisableRetry(TestData &data) +TEST_F(ResenderTest, test_disable_retry) { + auto& data = *_data; data._retryPolicy->setEnabled(false); EXPECT_TRUE(data._srcSession->send(createMessage("msg"), Route::parse("dst/session")).isAccepted()); Message::UP msg = data._dstHandler.getMessage(GET_MESSAGE_TIMEOUT); @@ -244,16 +221,16 @@ Test::testDisableRetry(TestData &data) printf("%s", reply->getTrace().toString().c_str()); } -void -Test::testRetryDelay(TestData &data) +TEST_F(ResenderTest, test_retry_delay) { + auto& data = *_data; data._retryPolicy->setEnabled(true); data._retryPolicy->setBaseDelay(0.01); EXPECT_TRUE(data._srcSession->send(createMessage("msg"), Route::parse("dst/session")).isAccepted()); Message::UP msg = data._dstHandler.getMessage(GET_MESSAGE_TIMEOUT); ASSERT_TRUE(msg); for (uint32_t i = 0; i < 5; ++i) { - EXPECT_EQUAL(i, msg->getRetry()); + EXPECT_EQ(i, msg->getRetry()); replyFromDestination(data, std::move(msg), ErrorCode::APP_TRANSIENT_ERROR, -1); msg = data._dstHandler.getMessage(GET_MESSAGE_TIMEOUT); ASSERT_TRUE(msg); @@ -273,16 +250,16 @@ Test::testRetryDelay(TestData &data) EXPECT_TRUE(trace.find("retry 5 in 0.160") != string::npos); } -void -Test::testRequestRetryDelay(TestData &data) +TEST_F(ResenderTest, test_request_retry_delay) { + auto& data = *_data; data._retryPolicy->setEnabled(true); data._retryPolicy->setBaseDelay(1); EXPECT_TRUE(data._srcSession->send(createMessage("msg"), Route::parse("dst/session")).isAccepted()); Message::UP msg = data._dstHandler.getMessage(GET_MESSAGE_TIMEOUT); ASSERT_TRUE(msg); for (uint32_t i = 0; i < 5; ++i) { - EXPECT_EQUAL(i, msg->getRetry()); + EXPECT_EQ(i, msg->getRetry()); replyFromDestination(data, std::move(msg), ErrorCode::APP_TRANSIENT_ERROR, i / 50.0); msg = data._dstHandler.getMessage(GET_MESSAGE_TIMEOUT); ASSERT_TRUE(msg); @@ -302,3 +279,4 @@ Test::testRequestRetryDelay(TestData &data) EXPECT_TRUE(trace.find("retry 5 in 0.080") != string::npos); } +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 |