//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotCountBytesAlreadyInBuffer() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotCountBytesAlreadyInBuffer() { // Given int sizeLimit = 100; ByteBuf buffer = Unpooled.buffer(); int padding = Long.BYTES; buffer.writeLong(0); BoundedNetworkWritableChannel channel = new BoundedNetworkWritableChannel(buffer, sizeLimit); // When for (int i = 0; i < sizeLimit - padding; i++) { channel.Put(( sbyte )0); } // then it should be ok // again, when for (int i = 0; i < padding; i++) { channel.Put(( sbyte )0); } // then again, it should work // finally, when we pass the limit try { channel.Put(( sbyte )0); fail("Should not allow more bytes than what the limit dictates"); } catch (MessageTooBigException) { // then } }
//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(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowExceptionForHalfWrittenInstance() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowExceptionForHalfWrittenInstance() { // given // a CoreMember and a ByteBuffer to write it to MemberId.Marshal marshal = new MemberId.Marshal(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId aRealMember = new org.neo4j.causalclustering.identity.MemberId(java.util.UUID.randomUUID()); MemberId aRealMember = new MemberId(System.Guid.randomUUID()); ByteBuf buffer = Unpooled.buffer(1000); // and the CoreMember is serialized but for 5 bytes at the end marshal.MarshalConflict(aRealMember, new BoundedNetworkWritableChannel(buffer)); ByteBuf bufferWithMissingBytes = buffer.copy(0, buffer.writerIndex() - 5); // when try { marshal.Unmarshal(new NetworkReadableClosableChannelNetty4(bufferWithMissingBytes)); fail("Should have thrown exception"); } catch (EndOfStreamException) { // expected } }
//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(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void contentEquals(org.neo4j.causalclustering.core.replication.ReplicatedContent one, org.neo4j.causalclustering.core.replication.ReplicatedContent two) throws Exception private void ContentEquals(ReplicatedContent one, ReplicatedContent two) { if (one is ReplicatedTransaction) { ByteBuf buffer1 = Unpooled.buffer(); ByteBuf buffer2 = Unpooled.buffer(); Encode(buffer1, (( ReplicatedTransaction )one).encode()); Encode(buffer2, (( ReplicatedTransaction )two).encode()); assertEquals(buffer1, buffer2); } else if (one is DistributedOperation) { assertEquals((( DistributedOperation )one).globalSession(), ((DistributedOperation)two).globalSession()); assertEquals((( DistributedOperation )one).operationId(), ((DistributedOperation)two).operationId()); ContentEquals((( DistributedOperation )one).content(), ((DistributedOperation)two).content()); } else { assertEquals(one, two); } }
//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(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void sizeLimitShouldWorkWithArrays() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void SizeLimitShouldWorkWithArrays() { // Given int sizeLimit = 100; BoundedNetworkWritableChannel channel = new BoundedNetworkWritableChannel(Unpooled.buffer(), sizeLimit); // When int padding = 10; for (int i = 0; i < sizeLimit - padding; i++) { channel.Put(( sbyte )0); } try { channel.Put(new sbyte[padding * 2], padding * 2); fail("Should not allow more bytes than what the limit dictates"); } catch (MessageTooBigException) { // then } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRespectSizeLimit() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldRespectSizeLimit() { // Given int sizeLimit = 100; BoundedNetworkWritableChannel channel = new BoundedNetworkWritableChannel(Unpooled.buffer(), sizeLimit); // when for (int i = 0; i < sizeLimit; i++) { channel.Put(( sbyte )1); } try { channel.Put(( sbyte )1); fail("Should not allow more bytes than what the limit dictates"); } catch (MessageTooBigException) { // then } }