mil.dod.th.ose.remote.integration/src/mil/dod/th/ose/remote/integration/base/TestSocketChannel.java
@Test
    public void testGarbage() throws UnknownHostException, IOException
    {
        try (Socket socket = SocketHostHelper.connectToController())
        {
            // complete garbage message, first byte is the varint for the octet count to follow (so total size is 4)
            socket.getOutputStream().write(new byte[] {0x3, 0x67, 0x11, 0x22});
            
            // incomplete message
            TerraHarvestMessage message = TerraHarvestMessage.getDefaultInstance();
            message.writeDelimitedTo(socket.getOutputStream());
            
            // send out real message to ensure it is still accepted
            TerraHarvestMessage request = TerraHarvestMessageHelper.createRequestControllerInfoMsg();
            request.writeDelimitedTo(socket.getOutputStream());
            
            // read in response
            TerraHarvestMessage response = TerraHarvestMessage.parseDelimitedFrom(socket.getInputStream());
            TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(response.getTerraHarvestPayload());
            assertThat(response, is(notNullValue()));
            assertThat(payLoadTest.getNamespace(), is(Namespace.Base));
        }
    }
/**
     * Verify sending garbage data won't trip up the channel.
     */
Verify sending garbage data won't trip up the channel.
Verify sending garbage data won ' t trip up the channel .
@Test
    public void testGarbage() throws UnknownHostException, IOException
    {
        try (Socket socket = SocketHostHelper.connectToController())
        {
            socket.getOutputStream().write(new byte[] {0x3, 0x67, 0x11, 0x22});
            TerraHarvestMessage message = TerraHarvestMessage.getDefaultInstance();
            message.writeDelimitedTo(socket.getOutputStream());
            TerraHarvestMessage request = TerraHarvestMessageHelper.createRequestControllerInfoMsg();
            request.writeDelimitedTo(socket.getOutputStream());
            TerraHarvestMessage response = TerraHarvestMessage.parseDelimitedFrom(socket.getInputStream());
            TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(response.getTerraHarvestPayload());
            assertThat(response, is(notNullValue()));
            assertThat(payLoadTest.getNamespace(), is(Namespace.Base));
        }
    }
@ Test public void testGarbage ( ) throws UnknownHostException , IOException { try ( Socket socket = SocketHostHelper . connectToController ( ) ) { socket . getOutputStream ( ) . write ( new byte [ ] { 0x3 , 0x67 , 0x11 , 0x22 } ) ; TerraHarvestMessage message = TerraHarvestMessage . getDefaultInstance ( ) ; message . writeDelimitedTo ( socket . getOutputStream ( ) ) ; TerraHarvestMessage request = TerraHarvestMessageHelper . createRequestControllerInfoMsg ( ) ; request . writeDelimitedTo ( socket . getOutputStream ( ) ) ; TerraHarvestMessage response = TerraHarvestMessage . parseDelimitedFrom ( socket . getInputStream ( ) ) ; TerraHarvestPayload payLoadTest = TerraHarvestPayload . parseFrom ( response . getTerraHarvestPayload ( ) ) ; assertThat ( response , is ( notNullValue ( ) ) ) ; assertThat ( payLoadTest . getNamespace ( ) , is ( Namespace . Base ) ) ; } }
Verify sending garbage data won't trip up the channel.
Verify sending garbage data won ' t trip up the channel .
// complete garbage message, first byte is the varint for the octet count to follow (so total size is 4) // incomplete message // send out real message to ensure it is still accepted // read in response