/******************************************************************************** * Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ #include #include #include #include #include #include #include #include #include namespace { using namespace std; using namespace fair::mq; TEST(Channel, Validation) { Channel channel; ASSERT_THROW(channel.Validate(), Channel::ChannelConfigurationError); channel.UpdateType("pair"); ASSERT_FALSE(channel.Validate()); ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("bla"); ASSERT_THROW(channel.Validate(), Channel::ChannelConfigurationError); channel.UpdateMethod("connect"); ASSERT_FALSE(channel.Validate()); ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("ipc://"); ASSERT_FALSE(channel.Validate()); ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("verbs://"); ASSERT_FALSE(channel.Validate()); ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("inproc://"); ASSERT_FALSE(channel.Validate()); ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("tcp://"); ASSERT_FALSE(channel.Validate()); ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("tcp://localhost:5555"); ASSERT_TRUE(channel.Validate()); ASSERT_TRUE(channel.IsValid()); channel.UpdateSndBufSize(-1); ASSERT_THROW(channel.Validate(), Channel::ChannelConfigurationError); channel.UpdateSndBufSize(1000); ASSERT_NO_THROW(channel.Validate()); channel.UpdateRcvBufSize(-1); ASSERT_THROW(channel.Validate(), Channel::ChannelConfigurationError); channel.UpdateRcvBufSize(1000); ASSERT_NO_THROW(channel.Validate()); channel.UpdateSndKernelSize(-1); ASSERT_THROW(channel.Validate(), Channel::ChannelConfigurationError); channel.UpdateSndKernelSize(1000); ASSERT_NO_THROW(channel.Validate()); channel.UpdateRcvKernelSize(-1); ASSERT_THROW(channel.Validate(), Channel::ChannelConfigurationError); channel.UpdateRcvKernelSize(1000); ASSERT_NO_THROW(channel.Validate()); channel.UpdateRateLogging(-1); ASSERT_THROW(channel.Validate(), Channel::ChannelConfigurationError); channel.UpdateRateLogging(1); ASSERT_NO_THROW(channel.Validate()); Channel channel2 = channel; ASSERT_NO_THROW(channel2.Validate()); ASSERT_TRUE(channel2.Validate()); ASSERT_TRUE(channel2.IsValid()); ASSERT_TRUE(channel2.Validate()); channel2.UpdateName("Kanal"); ASSERT_EQ(channel2.GetName(), "Kanal"); channel2.Invalidate(); ASSERT_FALSE(channel2.IsValid()); ASSERT_TRUE(channel2.Validate()); } auto testConnectedPeers(std::string const& transport) { ProgOptions config; test::Configure(config); test::IpcAddress const address("connected_peers"); unsigned long constexpr zero(0), one(1); auto factory(TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config)); Channel ch1("ch1", "pair", factory); ASSERT_EQ(ch1.GetNumberOfConnectedPeers(), zero); ASSERT_TRUE(ch1.Bind(address)); ASSERT_EQ(ch1.GetNumberOfConnectedPeers(), zero); { Channel ch2("ch2", "pair", factory); ASSERT_EQ(ch2.GetNumberOfConnectedPeers(), zero); ASSERT_TRUE(ch2.Connect(address)); ASSERT_TRUE(test::WaitUntil([&] { return ch1.GetNumberOfConnectedPeers() == one; })); ASSERT_TRUE(test::WaitUntil([&] { return ch2.GetNumberOfConnectedPeers() == one; })); } ASSERT_TRUE(test::WaitUntil([&] { return ch1.GetNumberOfConnectedPeers() == zero; })); } using ConnectedPeers = test::TransportTest; TEST_P(ConnectedPeers, Pair) { testConnectedPeers(GetParam().transport); } INSTANTIATE_TEST_SUITE_P(, ConnectedPeers, test::BasicTransports(), test::TransportParamName()); } /* namespace */