Beispiel #1
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)));
        }
Beispiel #2
0
            internal Fixture(Parameters parameters)
            {
                ApplicationProtocolRepository serverApplicationProtocolRepository = new ApplicationProtocolRepository(TestProtocols_TestApplicationProtocols.values(), parameters.ServerApplicationProtocol);
                ModifierProtocolRepository    serverModifierProtocolRepository    = new ModifierProtocolRepository(TestProtocols_TestModifierProtocols.values(), parameters.ServerModifierProtocols);

                ClientApplicationProtocolRepository = new ApplicationProtocolRepository(TestProtocols_TestApplicationProtocols.values(), parameters.ClientApplicationProtocol);
                ClientModifierProtocolRepository    = new ModifierProtocolRepository(TestProtocols_TestModifierProtocols.values(), parameters.ClientModifierProtocols);

                HandshakeClient = new HandshakeClient();
                HandshakeServer = new HandshakeServer(serverApplicationProtocolRepository, serverModifierProtocolRepository, new FakeServerChannel(HandshakeClient));
                ClientChannel   = new FakeClientChannel(HandshakeServer);
                this.Parameters = parameters;
            }
Beispiel #3
0
        private NettyHandshakeServer CreateHandshakeServer(SocketChannel channel)
        {
            HandshakeServer handshakeServer = new HandshakeServer(_applicationProtocolRepository, _modifierProtocolRepository, new SimpleNettyChannel(channel, _log)
                                                                  );

            handshakeServer.ProtocolStackFuture().whenComplete((protocolStack, failure) => onHandshakeComplete(protocolStack, channel, failure));
            channel.closeFuture().addListener(f =>
            {
                try
                {
                    channel.parent().pipeline().fireUserEventTriggered(new ServerHandshakeFinishedEvent_Closed(ToSocketAddress(channel)));
                }
                catch (RejectedExecutionException)
                {
                }
            });
            return(new NettyHandshakeServer(handshakeServer));
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = ServerHandshakeException.class) public void shouldFailHandshakeForUnknownProtocolOnServer() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailHandshakeForUnknownProtocolOnServer()
        {
            // given
            HandshakeServer handshakeServer = new HandshakeServer(_raftApplicationProtocolRepository, _modifierProtocolRepository, new ProtocolHandshakeHappyTest.FakeServerChannel(_handshakeClient));
            Channel         clientChannel   = new ProtocolHandshakeHappyTest.FakeClientChannel(handshakeServer);

            // when
            _handshakeClient.initiate(clientChannel, _catchupApplicationProtocolRepository, _modifierProtocolRepository);
            CompletableFuture <ProtocolStack> serverHandshakeFuture = handshakeServer.ProtocolStackFuture();

            // then
            try
            {
                serverHandshakeFuture.getNow(null);
            }
            catch (CompletionException ex)
            {
                throw ex.InnerException;
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSuccessfullySwitchOverWhenServerHasConfiguredRaftVersions()
        public void shouldSuccessfullySwitchOverWhenServerHasConfiguredRaftVersions()
        {
            // given
            ISet <int> requestedVersions         = asSet(TestProtocols_TestApplicationProtocols.allVersionsOf(RAFT));
            int?       expectedNegotiatedVersion = 1;
            ApplicationProtocolRepository applicationProtocolRepository = new ApplicationProtocolRepository(TestProtocols_TestApplicationProtocols.values(), new ApplicationSupportedProtocols(RAFT, singletonList(expectedNegotiatedVersion)));

            HandshakeServer server = new HandshakeServer(applicationProtocolRepository, _modifierProtocolRepository, _channel);

            server.Handle(InitialMagicMessage.Instance());
            server.Handle(new ApplicationProtocolRequest(RAFT.canonicalName(), requestedVersions));

            // when
            server.Handle(new SwitchOverRequest(RAFT_1.category(), expectedNegotiatedVersion.Value, emptyList()));

            // then
            verify(_channel).writeAndFlush(InitialMagicMessage.Instance());
            verify(_channel).writeAndFlush(new SwitchOverResponse(SUCCESS));
            ProtocolStack protocolStack         = server.ProtocolStackFuture().getNow(null);
            ProtocolStack expectedProtocolStack = new ProtocolStack(applicationProtocolRepository.Select(RAFT.canonicalName(), expectedNegotiatedVersion.Value).get(), emptyList());

            assertThat(protocolStack, equalTo(expectedProtocolStack));
        }
Beispiel #6
0
 private void InitializeInstanceFields()
 {
     _applicationProtocolRepository = new ApplicationProtocolRepository(TestProtocols_TestApplicationProtocols.values(), _supportedApplicationProtocol);
     _server = new HandshakeServer(_applicationProtocolRepository, _modifierProtocolRepository, _channel);
 }
Beispiel #7
0
 public NettyHandshakeServer(HandshakeServer handler)
 {
     this._handler = handler;
 }
Beispiel #8
0
 internal FakeClientChannel(HandshakeServer handshakeServer) : base()
 {
     this.HandshakeServer = handshakeServer;
 }