예제 #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();
        }