//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ParameterizedTest(name = "V{0}") @ValueSource(longs = {org.neo4j.bolt.v1.BoltProtocolV1.VERSION, org.neo4j.bolt.v2.BoltProtocolV2.VERSION, org.neo4j.bolt.v3.BoltProtocolV3.VERSION}) void shouldCreateBoltProtocol(long protocolVersion) throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldCreateBoltProtocol(long protocolVersion) { EmbeddedChannel channel = new EmbeddedChannel(); BoltChannel boltChannel = new BoltChannel("bolt-1", "bolt", channel); BoltStateMachineFactory stateMachineFactory = mock(typeof(BoltStateMachineFactory)); BoltStateMachine stateMachine = mock(typeof(BoltStateMachine)); when(stateMachineFactory.NewStateMachine(protocolVersion, boltChannel)).thenReturn(stateMachine); BoltConnectionFactory connectionFactory = mock(typeof(BoltConnectionFactory)); BoltConnection connection = mock(typeof(BoltConnection)); when(connectionFactory.NewConnection(boltChannel, stateMachine)).thenReturn(connection); BoltProtocolFactory factory = new DefaultBoltProtocolFactory(connectionFactory, stateMachineFactory, NullLogService.Instance); BoltProtocol protocol = factory(protocolVersion, boltChannel); protocol.Install(); // handler with correct version is created assertEquals(protocolVersion, protocol.Version()); // it uses the expected worker verify(connectionFactory).newConnection(eq(boltChannel), any(typeof(BoltStateMachine))); // and halts this same worker when closed verify(connection, never()).stop(); channel.close(); verify(connection).stop(); channel.finishAndReleaseAll(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleFragmentedMessage() public virtual void ShouldHandleFragmentedMessage() { // Given BoltProtocol protocol = NewBoltProtocol(1); BoltProtocolFactory handlerFactory = NewProtocolFactory(1, protocol); EmbeddedChannel channel = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, false, true)); // When channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x60, ( sbyte )0x60, unchecked (( sbyte )0xB0) })); assertEquals(0, channel.outboundMessages().size()); channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x17, 0, 0, 0 })); assertEquals(0, channel.outboundMessages().size()); channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { 0, 0, 0 })); assertEquals(0, channel.outboundMessages().size()); channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { 0, 1, 0, 0, 0 })); assertEquals(0, channel.outboundMessages().size()); channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { 0, 0, 0 })); assertEquals(0, channel.outboundMessages().size()); channel.writeInbound(Unpooled.wrappedBuffer(new sbyte[] { 0, 0 })); // Then assertEquals(1, channel.outboundMessages().size()); assertByteBufEquals(Unpooled.buffer().writeInt(1), channel.readOutbound()); Thrown.expect(typeof(NoSuchElementException)); channel.pipeline().remove(typeof(ProtocolHandshaker)); assertTrue(channel.Active); verify(protocol).install(); }
private static BoltProtocol NewBoltProtocol(long version) { BoltProtocol handler = mock(typeof(BoltProtocol)); when(handler.Version()).thenReturn(version); return(handler); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldCreateNothingForUnknownProtocolVersion() internal virtual void ShouldCreateNothingForUnknownProtocolVersion() { int protocolVersion = 42; BoltChannel channel = BoltTestUtil.newTestBoltChannel(); BoltProtocolFactory factory = new DefaultBoltProtocolFactory(mock(typeof(BoltConnectionFactory)), mock(typeof(BoltStateMachineFactory)), NullLogService.Instance); BoltProtocol protocol = factory(protocolVersion, channel); // handler is not created assertNull(protocol); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRejectIfInsecureWhenEncryptionRequired() public virtual void ShouldRejectIfInsecureWhenEncryptionRequired() { // Given BoltProtocol protocol = NewBoltProtocol(1); BoltProtocolFactory handlerFactory = NewProtocolFactory(1, protocol); EmbeddedChannel channel = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, true, false)); // When ByteBuf input = Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x60, ( sbyte )0x60, unchecked (( sbyte )0xB0), ( sbyte )0x17 }, new sbyte[] { 0, 0, 0, 1 }, new sbyte[] { 0, 0, 0, 2 }, new sbyte[] { 0, 0, 0, 3 }, new sbyte[] { 0, 0, 0, 4 }); // fourth choice - no protocol channel.writeInbound(input); // Then assertEquals(0, channel.outboundMessages().size()); assertFalse(channel.Active); verify(protocol, never()).install(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRejectIfHttp() public virtual void ShouldRejectIfHttp() { // Given BoltProtocol protocol = NewBoltProtocol(1); BoltProtocolFactory handlerFactory = NewProtocolFactory(1, protocol); EmbeddedChannel channel = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, false, true)); // When FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://hello_world:10000"); request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, 0); channel.writeInbound(request); // Then assertEquals(0, channel.outboundMessages().size()); assertFalse(channel.Active); verify(protocol, never()).install(); _logProvider.assertExactly(AssertableLogProvider.inLog(typeof(ProtocolHandshaker)).warn("Unsupported connection type: 'HTTP'. Bolt protocol only operates over a TCP connection or WebSocket.")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFallbackToNoProtocolIfNoMatch() public virtual void ShouldFallbackToNoProtocolIfNoMatch() { // Given BoltProtocol protocol = NewBoltProtocol(1); BoltProtocolFactory handlerFactory = NewProtocolFactory(1, protocol); EmbeddedChannel channel = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, false, true)); // When ByteBuf input = Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x60, ( sbyte )0x60, unchecked (( sbyte )0xB0), ( sbyte )0x17 }, new sbyte[] { 0, 0, 0, 0 }, new sbyte[] { 0, 0, 0, 2 }, new sbyte[] { 0, 0, 0, 3 }, new sbyte[] { 0, 0, 0, 4 }); // fourth choice - no protocol channel.writeInbound(input); // Then assertEquals(1, channel.outboundMessages().size()); assertByteBufEquals(Unpooled.buffer().writeInt(0), channel.readOutbound()); assertFalse(channel.Active); verify(protocol, never()).install(); }
private bool PerformHandshake() { long[] suggestions = new long[4]; for (int i = 0; i < 4; i++) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long suggestion = handshakeBuffer.getInt((i + 1) * Integer.BYTES) & 0xFFFFFFFFL; long suggestion = _handshakeBuffer.getInt((i + 1) * Integer.BYTES) & 0xFFFFFFFFL; _protocol = _boltProtocolFactory(suggestion, _boltChannel); if (_protocol != null) { break; } suggestions[i] = suggestion; } if (_protocol == null) { _log.debug("Failed Bolt handshake: Bolt versions suggested by client '%s' are not supported by this server.", Arrays.ToString(suggestions)); } return(_protocol != null); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleMaxVersionNumber() public virtual void ShouldHandleMaxVersionNumber() { long maxVersionNumber = 4_294_967_295L; // Given BoltProtocol protocol = NewBoltProtocol(maxVersionNumber); BoltProtocolFactory handlerFactory = NewProtocolFactory(maxVersionNumber, protocol); EmbeddedChannel channel = new EmbeddedChannel(new ProtocolHandshaker(handlerFactory, _boltChannel, _logProvider, false, true)); // When ByteBuf input = Unpooled.wrappedBuffer(new sbyte[] { ( sbyte )0x60, ( sbyte )0x60, unchecked (( sbyte )0xB0), ( sbyte )0x17 }, new sbyte[] { unchecked (( sbyte )0xFF), unchecked (( sbyte )0xFF), unchecked (( sbyte )0xFF), unchecked (( sbyte )0xFF) }, new sbyte[] { 0, 0, 0, 0 }, new sbyte[] { 0, 0, 0, 0 }, new sbyte[] { 0, 0, 0, 0 }); // fourth choice - no protocol channel.writeInbound(input); // Then assertEquals(1, channel.outboundMessages().size()); assertByteBufEquals(Unpooled.buffer().writeInt((int)maxVersionNumber), channel.readOutbound()); Thrown.expect(typeof(NoSuchElementException)); channel.pipeline().remove(typeof(ProtocolHandshaker)); assertTrue(channel.Active); verify(protocol).install(); }
private static BoltProtocolFactory NewProtocolFactory(long version, BoltProtocol protocol) { return((givenVersion, channel) => version == givenVersion ? protocol : null); }