Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCompleteProtocolStackOnSuccessfulSwitchOverWithModifierProtocols()
        public void shouldCompleteProtocolStackOnSuccessfulSwitchOverWithModifierProtocols()
        {
            // given
            _server.handle(InitialMagicMessage.Instance());
            _server.handle(new ApplicationProtocolRequest(RAFT.canonicalName(), asSet(RAFT_1.implementation())));
            _server.handle(new ModifierProtocolRequest(COMPRESSION.canonicalName(), asSet(SNAPPY.implementation())));
            _server.handle(new ModifierProtocolRequest(GRATUITOUS_OBFUSCATION.canonicalName(), asSet(ROT13.implementation())));

            // when
            IList <Pair <string, string> > modifierRequest = new IList <Pair <string, string> > {
                Pair.of(SNAPPY.category(), SNAPPY.implementation()), Pair.of(ROT13.category(), ROT13.implementation())
            };

            _server.handle(new SwitchOverRequest(RAFT_1.category(), RAFT_1.implementation(), modifierRequest));

            // then
            verify(_channel).writeAndFlush(InitialMagicMessage.Instance());
            verify(_channel).writeAndFlush(new SwitchOverResponse(SUCCESS));
            ProtocolStack            protocolStack = _server.protocolStackFuture().getNow(null);
            IList <ModifierProtocol> modifiers     = new IList <ModifierProtocol> {
                SNAPPY, ROT13
            };

            assertThat(protocolStack, equalTo(new ProtocolStack(RAFT_1, modifiers)));
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCompleteProtocolStackOnSuccessfulSwitchOverWithConfiguredModifierProtocols()
        public void shouldCompleteProtocolStackOnSuccessfulSwitchOverWithConfiguredModifierProtocols()
        {
            // given
            ISet <string>  requestedVersions         = asSet(TestProtocols_TestModifierProtocols.allVersionsOf(COMPRESSION));
            string         expectedNegotiatedVersion = SNAPPY.implementation();
            IList <string> configuredVersions        = singletonList(expectedNegotiatedVersion);

            IList <ModifierSupportedProtocols> supportedModifierProtocols = asList(new ModifierSupportedProtocols(COMPRESSION, configuredVersions));

            ModifierProtocolRepository modifierProtocolRepository = new ModifierProtocolRepository(TestProtocols_TestModifierProtocols.values(), supportedModifierProtocols);

            HandshakeServer server = new HandshakeServer(_applicationProtocolRepository, modifierProtocolRepository, _channel);

            server.Handle(InitialMagicMessage.Instance());
            server.Handle(new ApplicationProtocolRequest(RAFT.canonicalName(), asSet(RAFT_1.implementation())));
            server.Handle(new ModifierProtocolRequest(COMPRESSION.canonicalName(), requestedVersions));

            // when
            IList <Pair <string, string> > modifierRequest = new IList <Pair <string, string> > {
                Pair.of(SNAPPY.category(), SNAPPY.implementation())
            };

            server.Handle(new SwitchOverRequest(RAFT_1.category(), RAFT_1.implementation(), modifierRequest));

            // then
            verify(_channel).writeAndFlush(InitialMagicMessage.Instance());
            verify(_channel).writeAndFlush(new SwitchOverResponse(SUCCESS));
            ProtocolStack            protocolStack = server.ProtocolStackFuture().getNow(null);
            IList <ModifierProtocol> modifiers     = new IList <ModifierProtocol> {
                SNAPPY
            };

            assertThat(protocolStack, equalTo(new ProtocolStack(RAFT_1, modifiers)));
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAcceptCorrectMagicValue()
        public void shouldAcceptCorrectMagicValue()
        {
            // when
            _server.handle(InitialMagicMessage.Instance());

            // then
            AssertUnfinished();
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateWithCorrectMagicValue()
        public virtual void ShouldCreateWithCorrectMagicValue()
        {
            // given
            InitialMagicMessage magicMessage = InitialMagicMessage.Instance();

            // then
            assertTrue(magicMessage.CorrectMagic);
            assertEquals("NEO4J_CLUSTER", magicMessage.Magic());
        }
Пример #5
0
        public override void Handle(InitialMagicMessage magicMessage)
        {
            if (!magicMessage.CorrectMagic)
            {
                Decline("Incorrect magic value received");
            }
            // TODO: check clusterId as well

            _magicReceived = true;
        }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotThrowIfMagicHasBeenSent()
        public virtual void ShouldNotThrowIfMagicHasBeenSent()
        {
            // given
            InitialMagicMessage.Instance().dispatch(_client);

            // when
            Message.dispatch(_client);

            // then pass
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExceptionallyCompleteProtocolStackOnUnallowedApplicationProtocol()
        public void shouldExceptionallyCompleteProtocolStackOnUnallowedApplicationProtocol()
        {
            // given
            _server.handle(InitialMagicMessage.Instance());

            // when
            _server.handle(new ApplicationProtocolRequest(TestProtocols_TestApplicationProtocols.CATCHUP_1.category(), asSet(TestProtocols_TestApplicationProtocols.CATCHUP_1.implementation())));

            // then
            AssertExceptionallyCompletedProtocolStackFuture();
        }
Пример #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDeclineUnallowedApplicationProtocol()
        public void shouldDeclineUnallowedApplicationProtocol()
        {
            // given
            _server.handle(InitialMagicMessage.Instance());

            // when
            _server.handle(new ApplicationProtocolRequest(TestProtocols_TestApplicationProtocols.CATCHUP_1.category(), asSet(TestProtocols_TestApplicationProtocols.CATCHUP_1.implementation())));

            // then
            verify(_channel).dispose();
        }
Пример #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAcceptCorrectMagic()
        public virtual void ShouldAcceptCorrectMagic()
        {
            // given
            CompletableFuture <ProtocolStack> protocolStackCompletableFuture = _client.initiate(_channel, _applicationProtocolRepository, _modifierProtocolRepository);

            // when
            _client.handle(InitialMagicMessage.Instance());

            // then
            assertFalse(protocolStackCompletableFuture.Done);
        }
Пример #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCloseConnectionIfKnownApplicationProtocol()
        public void shouldNotCloseConnectionIfKnownApplicationProtocol()
        {
            // given
            ISet <int> versions = asSet(1, 2, 3);

            _server.handle(InitialMagicMessage.Instance());

            // when
            _server.handle(new ApplicationProtocolRequest(RAFT.canonicalName(), versions));

            // then
            AssertUnfinished();
        }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSendApplicationProtocolResponseForKnownProtocol()
        public void shouldSendApplicationProtocolResponseForKnownProtocol()
        {
            // given
            ISet <int> versions = asSet(1, 2, 3);

            _server.handle(InitialMagicMessage.Instance());

            // when
            _server.handle(new ApplicationProtocolRequest(RAFT.canonicalName(), versions));

            // then
            verify(_channel).writeAndFlush(new ApplicationProtocolResponse(SUCCESS, TestProtocols_TestApplicationProtocols.RAFT_3.category(), TestProtocols_TestApplicationProtocols.RAFT_3.implementation()));
        }
Пример #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExceptionallyCompleteProtocolStackWhenApplicationProtocolResponseForUnsupportedVersion()
        public virtual void ShouldExceptionallyCompleteProtocolStackWhenApplicationProtocolResponseForUnsupportedVersion()
        {
            // given
            CompletableFuture <ProtocolStack> protocolStackCompletableFuture = _client.initiate(_channel, _applicationProtocolRepository, _modifierProtocolRepository);

            _client.handle(InitialMagicMessage.Instance());

            // when
            _client.handle(new ApplicationProtocolResponse(StatusCode.Success, _applicationProtocolIdentifier.canonicalName(), int.MaxValue));

            // then
            AssertCompletedExceptionally(protocolStackCompletableFuture);
        }
Пример #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExceptionallyCompleteProtocolStackWhenProtocolStackNotSet()
        public virtual void ShouldExceptionallyCompleteProtocolStackWhenProtocolStackNotSet()
        {
            // given
            CompletableFuture <ProtocolStack> protocolStackCompletableFuture = _client.initiate(_channel, _applicationProtocolRepository, _modifierProtocolRepository);

            _client.handle(InitialMagicMessage.Instance());

            // when
            _client.handle(new SwitchOverResponse(StatusCode.Success));

            // then
            AssertCompletedExceptionally(protocolStackCompletableFuture);
        }
Пример #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCloseConnectionForGivenModifierProtocol()
        public void shouldNotCloseConnectionForGivenModifierProtocol()
        {
            // given
            ISet <string> versions = asSet(SNAPPY.implementation(), LZO.implementation(), LZ4.implementation());

            _server.handle(InitialMagicMessage.Instance());

            // when
            _server.handle(new ModifierProtocolRequest(COMPRESSION.canonicalName(), versions));

            // then
            AssertUnfinished();
        }
Пример #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExceptionallyCompleteProtocolStackForUnknownApplicationProtocol()
        public void shouldExceptionallyCompleteProtocolStackForUnknownApplicationProtocol()
        {
            // given
            ISet <int> versions = asSet(1, 2, 3);

            _server.handle(InitialMagicMessage.Instance());

            // when
            _server.handle(new ApplicationProtocolRequest("UNKNOWN", versions));

            // then
            AssertExceptionallyCompletedProtocolStackFuture();
        }
Пример #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExceptionallyCompleteProtocolStackIfSwitchOverBeforeNegotiation()
        public void shouldExceptionallyCompleteProtocolStackIfSwitchOverBeforeNegotiation()
        {
            // given
            int version = 1;

            _server.handle(InitialMagicMessage.Instance());

            // when
            _server.handle(new SwitchOverRequest(RAFT_1.category(), version, emptyList()));

            // then
            AssertExceptionallyCompletedProtocolStackFuture();
        }
Пример #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExceptionallyCompleteProtocolStackWhenApplicationProtocolResponseForIncorrectProtocol()
        public virtual void ShouldExceptionallyCompleteProtocolStackWhenApplicationProtocolResponseForIncorrectProtocol()
        {
            // given
            CompletableFuture <ProtocolStack> protocolStackCompletableFuture = _client.initiate(_channel, _applicationProtocolRepository, _modifierProtocolRepository);

            _client.handle(InitialMagicMessage.Instance());

            // when
            _client.handle(new ApplicationProtocolResponse(StatusCode.Success, "zab", _raftVersion));

            // then
            AssertCompletedExceptionally(protocolStackCompletableFuture);
        }
Пример #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotSendSwitchOverRequestIfApplicationProtocolResponseNotReceivedOnModifierProtocolResponseReceive()
        public virtual void ShouldNotSendSwitchOverRequestIfApplicationProtocolResponseNotReceivedOnModifierProtocolResponseReceive()
        {
            // given
            CompletableFuture <ProtocolStack> protocolStackCompletableFuture = _client.initiate(_channel, _applicationProtocolRepository, _modifierProtocolRepository);

            _client.handle(InitialMagicMessage.Instance());

            // when
            _client.handle(new ModifierProtocolResponse(StatusCode.Success, ModifierProtocolCategory.COMPRESSION.canonicalName(), SNAPPY.implementation()));

            // then
            verify(_channel, never()).writeAndFlush(any(typeof(SwitchOverRequest)));
            assertFalse(protocolStackCompletableFuture.Done);
        }
Пример #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExceptionallyCompleteProtocolStackIfSwitchOverDiffersFromNegotiatedProtocol()
        public void shouldExceptionallyCompleteProtocolStackIfSwitchOverDiffersFromNegotiatedProtocol()
        {
            // given
            int version = 1;

            _server.handle(InitialMagicMessage.Instance());
            _server.handle(new ApplicationProtocolRequest(RAFT.canonicalName(), asSet(version)));

            // when
            _server.handle(new SwitchOverRequest(RAFT_1.category(), version + 1, emptyList()));

            // then
            AssertExceptionallyCompletedProtocolStackFuture();
        }
Пример #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSendSwitchOverRequestIfNoModifierProtocolsToRequestOnApplicationProtocolResponse()
        public virtual void ShouldSendSwitchOverRequestIfNoModifierProtocolsToRequestOnApplicationProtocolResponse()
        {
            ModifierProtocolRepository repo = new ModifierProtocolRepository(TestProtocols_TestModifierProtocols.values(), emptyList());
            // given
            CompletableFuture <ProtocolStack> protocolStackCompletableFuture = _client.initiate(_channel, _applicationProtocolRepository, repo);

            _client.handle(InitialMagicMessage.Instance());

            // when
            _client.handle(new ApplicationProtocolResponse(StatusCode.Success, _applicationProtocolIdentifier.canonicalName(), _raftVersion));

            // then
            verify(_channel).writeAndFlush(new SwitchOverRequest(_applicationProtocolIdentifier.canonicalName(), _raftVersion, emptyList()));
            assertFalse(protocolStackCompletableFuture.Done);
        }
Пример #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExceptionallyCompleteProtocolStackOnUnknownProtocolSwitchOver()
        public void shouldExceptionallyCompleteProtocolStackOnUnknownProtocolSwitchOver()
        {
            // given
            int    version             = 1;
            string unknownProtocolName = "UNKNOWN";

            _server.handle(InitialMagicMessage.Instance());
            _server.handle(new ApplicationProtocolRequest(unknownProtocolName, asSet(version)));

            // when
            _server.handle(new SwitchOverRequest(unknownProtocolName, version, emptyList()));

            // then
            AssertExceptionallyCompletedProtocolStackFuture();
        }
Пример #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSendFailModifierProtocolResponseForUnknownProtocol()
        public void shouldSendFailModifierProtocolResponseForUnknownProtocol()
        {
            // given
            ISet <string> versions = asSet(SNAPPY.implementation(), LZO.implementation(), LZ4.implementation());

            _server.handle(InitialMagicMessage.Instance());

            // when
            string protocolName = "let's just randomly reorder all the bytes";

            _server.handle(new ModifierProtocolRequest(protocolName, versions));

            // then
            verify(_channel).writeAndFlush(new ModifierProtocolResponse(FAILURE, protocolName, ""));
        }
Пример #23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCloseConnectionIfUnknownModifierProtocol()
        public void shouldNotCloseConnectionIfUnknownModifierProtocol()
        {
            // given
            ISet <string> versions = asSet(SNAPPY.implementation(), LZO.implementation(), LZ4.implementation());

            _server.handle(InitialMagicMessage.Instance());

            // when
            string protocolName = "let's just randomly reorder all the bytes";

            _server.handle(new ModifierProtocolRequest(protocolName, versions));

            // then
            AssertUnfinished();
        }
Пример #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCloseConnectionIfUnknownModifierProtocolVersion()
        public void shouldNotCloseConnectionIfUnknownModifierProtocolVersion()
        {
            // given
            ISet <string> versions = asSet("not a real algorithm");

            _server.handle(InitialMagicMessage.Instance());

            // when
            string protocolName = COMPRESSION.canonicalName();

            _server.handle(new ModifierProtocolRequest(protocolName, versions));

            // then
            AssertUnfinished();
        }
Пример #25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSendFailModifierProtocolResponseForUnknownVersion()
        public void shouldSendFailModifierProtocolResponseForUnknownVersion()
        {
            // given
            ISet <string> versions = asSet("Not a real protocol");

            _server.handle(InitialMagicMessage.Instance());

            // when
            string protocolName = COMPRESSION.canonicalName();

            _server.handle(new ModifierProtocolRequest(protocolName, versions));

            // then
            verify(_channel).writeAndFlush(new ModifierProtocolResponse(FAILURE, protocolName, ""));
        }
Пример #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotSendSwitchOverRequestOnModifierProtocolResponseIfNotAllModifierProtocolResponsesReceived()
        public virtual void ShouldNotSendSwitchOverRequestOnModifierProtocolResponseIfNotAllModifierProtocolResponsesReceived()
        {
            // given
            CompletableFuture <ProtocolStack> protocolStackCompletableFuture = _client.initiate(_channel, _applicationProtocolRepository, _modifierProtocolRepository);

            _client.handle(InitialMagicMessage.Instance());
            _client.handle(new ApplicationProtocolResponse(StatusCode.Success, _applicationProtocolIdentifier.canonicalName(), _raftVersion));

            // when
            _client.handle(new ModifierProtocolResponse(StatusCode.Success, Org.Neo4j.causalclustering.protocol.Protocol_ModifierProtocolCategory.Compression.canonicalName(), "woot"));

            // then
            verify(_channel, never()).writeAndFlush(any(typeof(SwitchOverRequest)));
            assertFalse(protocolStackCompletableFuture.Done);
        }
Пример #27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSendModifierProtocolResponseForGivenProtocol()
        public void shouldSendModifierProtocolResponseForGivenProtocol()
        {
            // given
            ISet <string> versions = asSet(TestProtocols_TestModifierProtocols.allVersionsOf(COMPRESSION));

            _server.handle(InitialMagicMessage.Instance());

            // when
            _server.handle(new ModifierProtocolRequest(COMPRESSION.canonicalName(), versions));

            // then
            ModifierProtocol expected = TestProtocols_TestModifierProtocols.latest(COMPRESSION);

            verify(_channel).writeAndFlush(new ModifierProtocolResponse(SUCCESS, expected.category(), expected.implementation()));
        }
Пример #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSendFailureIfSwitchOverBeforeNegotiation()
        public void shouldSendFailureIfSwitchOverBeforeNegotiation()
        {
            // given
            int version = 1;

            _server.handle(InitialMagicMessage.Instance());

            // when
            _server.handle(new SwitchOverRequest(RAFT_1.category(), version, emptyList()));

            // then
            InOrder inOrder = Mockito.inOrder(_channel);

            inOrder.verify(_channel).writeAndFlush(new SwitchOverResponse(FAILURE));
            inOrder.verify(_channel).dispose();
        }
Пример #29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSendNegativeResponseAndCloseForUnknownApplicationProtocol()
        public void shouldSendNegativeResponseAndCloseForUnknownApplicationProtocol()
        {
            // given
            ISet <int> versions = asSet(1, 2, 3);

            _server.handle(InitialMagicMessage.Instance());

            // when
            _server.handle(new ApplicationProtocolRequest("UNKNOWN", versions));

            // then
            InOrder inOrder = Mockito.inOrder(_channel);

            inOrder.verify(_channel).writeAndFlush(ApplicationProtocolResponse.NoProtocol);
            inOrder.verify(_channel).dispose();
        }
Пример #30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExceptionallyCompleteProtocolStackIfSwitchOverDiffersByVersionFromNegotiatedModifiedProtocol()
        public void shouldExceptionallyCompleteProtocolStackIfSwitchOverDiffersByVersionFromNegotiatedModifiedProtocol()
        {
            // given
            int version = 1;

            _server.handle(InitialMagicMessage.Instance());
            _server.handle(new ApplicationProtocolRequest(RAFT.canonicalName(), asSet(version)));
            _server.handle(new ModifierProtocolRequest(COMPRESSION.canonicalName(), asSet(SNAPPY.implementation())));

            // when
            _server.handle(new SwitchOverRequest(RAFT_1.category(), version, new IList <Pair <string, string> > {
                Pair.of(COMPRESSION.canonicalName(), LZ4.implementation())
            }));

            // then
            AssertExceptionallyCompletedProtocolStackFuture();
        }