Package streamer.debug

Examples of streamer.debug.MockServer$Packet


      Class<? extends Packet> packetClass = (Class<? extends Packet>) packets[packetId];
      if (packetClass == null) {
        return null;
      }
      Constructor<? extends Packet> c = packetClass.getConstructor(new Class[]{});
      Packet r = c.newInstance(blank);

      return newInstance(packetId, r);
    } catch (SecurityException e) {
      throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
View Full Code Here


    syncFlushPacketQueue(packetWrappers);
  }

  public void syncFlushPacketQueue(MCCraftPacket[] packetWrappers) {
    while (!resyncQueue.isEmpty()) {
      Packet p = resyncQueue.pollFirst();
      if (p != null) {
        syncedSendPacket(p, packetWrappers);
      }
    }
  }
View Full Code Here

            pipeline.add(new Queue("queue")); // To decouple input and output

            pipeline.link("socket", "echo", "queue", "socket");

            final byte[] mockData = new byte[] {0x01, 0x02, 0x03};
            MockServer server = new MockServer(new Packet[] {new Packet("Server hello") {
                {
                    type = SERVER;
                    data = mockData;
                }
            }, new Packet("Client hello") {
                {
                    type = CLIENT;
                    data = mockData;
                }
            }, new Packet("Server hello") {
                {
                    type = SERVER;
                    data = mockData;
                }
            }, new Packet("Client hello") {
                {
                    type = CLIENT;
                    data = mockData;
                }
            }});
            server.start();
            InetSocketAddress address = server.getAddress();

            /*DEBUG*/System.out.println("Address: " + address);
            socketWrapper.connect(address);

        } catch (Exception e) {
View Full Code Here

            pipeline.add(new Queue("queue")); // To decouple input and output

            pipeline.link("socket", "echo", "queue", "socket");

            final byte[] mockData = new byte[] {0x01, 0x02, 0x03};
            MockServer server = new MockServer(new Packet[] {new Packet("Server hello") {
                {
                    type = SERVER;
                    data = mockData;
                }
            }, new Packet("Client hello") {
                {
                    type = CLIENT;
                    data = mockData;
                }
            }, new Packet("Server hello") {
                {
                    type = SERVER;
                    data = mockData;
                }
            }, new Packet("Client hello") {
                {
                    type = CLIENT;
                    data = mockData;
                }
            }});
            server.start();
            InetSocketAddress address = server.getAddress();

            socketWrapper.connect(address);

        } catch (Exception e) {
            e.printStackTrace(System.err);
View Full Code Here

    public void testIsMockServerCanRespond() throws Exception {

        final byte[] mockClientData = new byte[] {0x01, 0x02, 0x03};
        final byte[] mockServerData = new byte[] {0x03, 0x02, 0x01};

        MockServer server = new MockServer(new Packet[] {new Packet("Client hello") {
            {
                type = CLIENT;
                data = mockClientData;
            }
        }, new Packet("Server hello") {
            {
                type = SERVER;
                data = mockServerData;
            }
        }});

        server.start();

        // Connect to server and send and receive mock data

        Socket socket = SocketFactory.getDefault().createSocket();
        try {
            socket.connect(new InetSocketAddress("127.0.0.1", server.getAddress().getPort()));

            InputStream is = socket.getInputStream();
            OutputStream os = socket.getOutputStream();

            // Write mock data to server
            os.write(mockClientData);

            // Read data from server
            byte actualData[] = new byte[mockServerData.length];
            int actualDataLength = is.read(actualData);

            // Compare mock data with actual data
            assertEquals("Unexpected length of actual data read from server.", mockServerData.length, actualDataLength);

            for (int i = 0; i < actualDataLength; i++) {
                assertEquals("Unexpected byte #" + i + " in response", mockServerData[i], actualData[i]);
            }

            server.waitUntilShutdowned(1 * 1000 /* up to 1 second */);

            assertNull("Unexpected exception at mock server side.", server.getException());
            assertTrue("Server is not shutdowned at after conversation.", server.isShutdowned());

        } finally {
            socket.close();
        }
    }
View Full Code Here

        final byte[] mockServerData1 = new byte[] {0x03, 0x02, 0x01};

        final byte[] mockClientData2 = new byte[] {0x02, 0x04, 0x02, 0x03};
        final byte[] mockServerData2 = new byte[] {0x02, 0x02, 0x01, 0x04};

        MockServer server = new MockServer(new Packet[] {new Packet("Client hello") {
            {
                type = CLIENT;
                data = mockClientData1;
            }
        }, new Packet("Server hello") {
            {
                type = SERVER;
                data = mockServerData1;
            }
        }, new Packet("Upgrade connection to SSL") {
            {
                type = UPGRADE_TO_SSL;
            }
        }, new Packet("Client data over SSL") {
            {
                type = CLIENT;
                data = mockClientData2;
            }
        }, new Packet("Server data over SSL") {
            {
                type = SERVER;
                data = mockServerData2;
            }
        }});

        server.start();

        // Connect to server and send and receive mock data

        Socket socket = SocketFactory.getDefault().createSocket();
        try {
            InetSocketAddress address = new InetSocketAddress("127.0.0.1", server.getAddress().getPort());
            socket.connect(address);

            // Send hello data over plain connection
            {
                InputStream is = socket.getInputStream();
                OutputStream os = socket.getOutputStream();

                // Write mock data to server
                os.write(mockClientData1);

                // Read data from server
                byte actualData[] = new byte[mockServerData1.length];
                int actualDataLength = is.read(actualData);

                // Compare mock data with actual data
                assertEquals("Unexpected length of actual data read from server.", mockServerData1.length, actualDataLength);

                for (int i = 0; i < actualDataLength; i++) {
                    assertEquals("Unexpected byte #" + i + " in response", mockServerData1[i], actualData[i]);
                }
            }

            // Upgrade connection to SSL and send mock data
            {
                //System.setProperty("javax.net.debug", "ssl");

                final SSLSocketFactory sslSocketFactory = (SSLSocketFactory)SSLSocketFactory.getDefault();
                SSLSocket sslSocket = (SSLSocket)sslSocketFactory.createSocket(socket, address.getHostName(), address.getPort(), true);
                sslSocket.setEnabledCipherSuites(sslSocket.getSupportedCipherSuites());
                sslSocket.startHandshake();

                InputStream is = sslSocket.getInputStream();
                OutputStream os = sslSocket.getOutputStream();

                // Write mock data to server
                os.write(mockClientData2);

                // Read data from server
                byte actualData[] = new byte[mockServerData2.length];
                int actualDataLength = is.read(actualData);

                // Compare mock data with actual data
                assertEquals("Unexpected length of actual data read from server.", mockServerData2.length, actualDataLength);

                for (int i = 0; i < actualDataLength; i++) {
                    assertEquals("Unexpected byte #" + i + " in response", mockServerData2[i], actualData[i]);
                }

            }

            server.waitUntilShutdowned(1 * 1000 /* up to 1 second */);

            assertNull("Unexpected exception at mock server side.", server.getException());
            assertTrue("Server is not shutdowned at after conversation.", server.isShutdowned());
        } finally {
            socket.close();
        }

    }
View Full Code Here

    public void testIsMockServerCanRespond() throws Exception {

        final byte[] mockClientData = new byte[] {0x01, 0x02, 0x03};
        final byte[] mockServerData = new byte[] {0x03, 0x02, 0x01};

        MockServer server = new MockServer(new Packet[] {new Packet("Client hello") {
            {
                type = CLIENT;
                data = mockClientData;
            }
        }, new Packet("Server hello") {
            {
                type = SERVER;
                data = mockServerData;
            }
        }});

        server.start();

        // Connect to server and send and receive mock data

        Socket socket = SocketFactory.getDefault().createSocket();
        try {
            socket.connect(new InetSocketAddress("127.0.0.1", server.getAddress().getPort()));

            InputStream is = socket.getInputStream();
            OutputStream os = socket.getOutputStream();

            // Write mock data to server
            os.write(mockClientData);

            // Read data from server
            byte actualData[] = new byte[mockServerData.length];
            int actualDataLength = is.read(actualData);

            // Compare mock data with actual data
            assertEquals("Unexpected length of actual data read from server.", mockServerData.length, actualDataLength);

            for (int i = 0; i < actualDataLength; i++) {
                assertEquals("Unexpected byte #" + i + " in response", mockServerData[i], actualData[i]);
            }

            server.waitUntilShutdowned(1 * 1000 /* up to 1 second */);

            assertNull("Unexpected exception at mock server side.", server.getException());
            assertTrue("Server is not shutdowned at after conversation.", server.isShutdowned());

        } finally {
            socket.close();
        }
    }
View Full Code Here

        final byte[] mockServerData1 = new byte[] {0x03, 0x02, 0x01};

        final byte[] mockClientData2 = new byte[] {0x02, 0x04, 0x02, 0x03};
        final byte[] mockServerData2 = new byte[] {0x02, 0x02, 0x01, 0x04};

        MockServer server = new MockServer(new Packet[] {new Packet("Client hello") {
            {
                type = CLIENT;
                data = mockClientData1;
            }
        }, new Packet("Server hello") {
            {
                type = SERVER;
                data = mockServerData1;
            }
        }, new Packet("Upgrade connection to SSL") {
            {
                type = UPGRADE_TO_SSL;
            }
        }, new Packet("Client data over SSL") {
            {
                type = CLIENT;
                data = mockClientData2;
            }
        }, new Packet("Server data over SSL") {
            {
                type = SERVER;
                data = mockServerData2;
            }
        }});

        server.start();

        // Connect to server and send and receive mock data

        Socket socket = SocketFactory.getDefault().createSocket();
        try {
            InetSocketAddress address = new InetSocketAddress("127.0.0.1", server.getAddress().getPort());
            socket.connect(address);

            // Send hello data over plain connection
            {
                InputStream is = socket.getInputStream();
                OutputStream os = socket.getOutputStream();

                // Write mock data to server
                os.write(mockClientData1);

                // Read data from server
                byte actualData[] = new byte[mockServerData1.length];
                int actualDataLength = is.read(actualData);

                // Compare mock data with actual data
                assertEquals("Unexpected length of actual data read from server.", mockServerData1.length, actualDataLength);

                for (int i = 0; i < actualDataLength; i++) {
                    assertEquals("Unexpected byte #" + i + " in response", mockServerData1[i], actualData[i]);
                }
            }

            // Upgrade connection to SSL and send mock data
            {
                //System.setProperty("javax.net.debug", "ssl");

                final SSLSocketFactory sslSocketFactory = (SSLSocketFactory)SSLSocketFactory.getDefault();
                SSLSocket sslSocket = (SSLSocket)sslSocketFactory.createSocket(socket, address.getHostName(), address.getPort(), true);
                sslSocket.setEnabledCipherSuites(sslSocket.getSupportedCipherSuites());
                sslSocket.startHandshake();

                InputStream is = sslSocket.getInputStream();
                OutputStream os = sslSocket.getOutputStream();

                // Write mock data to server
                os.write(mockClientData2);

                // Read data from server
                byte actualData[] = new byte[mockServerData2.length];
                int actualDataLength = is.read(actualData);

                // Compare mock data with actual data
                assertEquals("Unexpected length of actual data read from server.", mockServerData2.length, actualDataLength);

                for (int i = 0; i < actualDataLength; i++) {
                    assertEquals("Unexpected byte #" + i + " in response", mockServerData2[i], actualData[i]);
                }

            }

            server.waitUntilShutdowned(1 * 1000 /* up to 1 second */);

            assertNull("Unexpected exception at mock server side.", server.getException());
            assertTrue("Server is not shutdowned at after conversation.", server.isShutdowned());
        } finally {
            socket.close();
        }

    }
View Full Code Here

            pipeline.add(new Queue("queue")); // To decouple input and output

            pipeline.link("socket", "echo", "queue", "socket");

            final byte[] mockData = new byte[] {0x01, 0x02, 0x03};
            MockServer server = new MockServer(new Packet[] {new Packet("Server hello") {
                {
                    type = SERVER;
                    data = mockData;
                }
            }, new Packet("Client hello") {
                {
                    type = CLIENT;
                    data = mockData;
                }
            }, new Packet("Server hello") {
                {
                    type = SERVER;
                    data = mockData;
                }
            }, new Packet("Client hello") {
                {
                    type = CLIENT;
                    data = mockData;
                }
            }});
            server.start();
            InetSocketAddress address = server.getAddress();

            /*DEBUG*/System.out.println("Address: " + address);
            socketWrapper.connect(address);

        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of streamer.debug.MockServer$Packet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.