Package com.facebook.nifty.client

Examples of com.facebook.nifty.client.NiftyClient


    private scribe.Client makeNiftyClient()
            throws TTransportException, InterruptedException
    {
        InetSocketAddress address = new InetSocketAddress("localhost", port);
        TBinaryProtocol tp = new TBinaryProtocol(new NiftyClient().connectSync(address));
        return new scribe.Client(tp);
    }
View Full Code Here


    @Test(timeOut = 2000)
    public void testSyncConnectTimeout() throws ConnectException, IOException
    {
        ServerSocket serverSocket = new ServerSocket(0);
        int port = serverSocket.getLocalPort();
        final NiftyClient client = new NiftyClient();
        try {
                client.connectSync(new InetSocketAddress(port),
                                   TEST_CONNECT_TIMEOUT,
                                   TEST_READ_TIMEOUT,
                                   TEST_WRITE_TIMEOUT,
                                   TEST_MAX_FRAME_SIZE);
        }
        catch (Throwable throwable) {
            if (isTimeoutException(throwable)) {
                return;
            }
            Throwables.propagate(throwable);
        }
        finally {
            client.close();
            serverSocket.close();
        }

        // Should never get here
        fail("Connection succeeded but failure was expected");
View Full Code Here

    public void testAsyncConnectTimeout() throws IOException
    {
        ServerSocket serverSocket = new ServerSocket(0);
        int port = serverSocket.getLocalPort();

        final NiftyClient client = new NiftyClient();
        try {
            ListenableFuture<FramedClientChannel> future =
                            client.connectAsync(new FramedClientConnector(new InetSocketAddress(port)),
                                                TEST_CONNECT_TIMEOUT,
                                                TEST_READ_TIMEOUT,
                                                TEST_WRITE_TIMEOUT,
                                                TEST_MAX_FRAME_SIZE);
            // Wait while NiftyClient attempts to connect the channel
            future.get();
        }
        catch (Throwable throwable) {
            if (isTimeoutException(throwable)) {
                return;
            }
            Throwables.propagate(throwable);
        }
        finally {
            client.close();
            serverSocket.close();
        }

        // Should never get here
        fail("Connection succeeded but failure was expected");
View Full Code Here

    @Test
    public void testServerDisconnect()
            throws Exception
    {
        startServer();
        final NiftyClient niftyClient = new NiftyClient();
        scribe.Client client = makeNiftyClient(niftyClient);
        new Thread()
        {
            @Override
            public void run()
            {
                try {
                    sleep(1000L);
                    bootstrap.stop();
                }
                catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
        }.start();

        int max = (int) (Math.random() * 100) + 10;
        int exceptionCount = 0;
        for (int i = 0; i < max; i++) {
            Thread.sleep(100L);
            try {
                client.Log(Arrays.asList(new LogEntry("hello", "world " + i)));
            }
            catch (TException e) {
                log.info("caught expected exception " + e.toString());
                exceptionCount++;
            }
        }
        Assert.assertTrue(exceptionCount > 0);

        niftyClient.close();
    }
View Full Code Here

    private scribe.Client makeNiftyClient()
            throws TTransportException, InterruptedException
    {
        InetSocketAddress address = new InetSocketAddress("localhost", port);
        TTransport transport = new NiftyClient().connectSync(scribe.Client.class, new FramedClientConnector(address));
        TBinaryProtocol tp = new TBinaryProtocol(transport);
        return new scribe.Client(tp);
    }
View Full Code Here

    @Test(timeOut = 2000)
    public void testSyncConnectTimeout() throws ConnectException, IOException
    {
        ServerSocket serverSocket = new ServerSocket(0);
        int port = serverSocket.getLocalPort();
        final NiftyClient client = new NiftyClient();
        try {
                client.connectSync(scribe.Client.class,
                                   new FramedClientConnector(new InetSocketAddress(port)),
                                   TEST_CONNECT_TIMEOUT,
                                   TEST_RECEIVE_TIMEOUT,
                                   TEST_READ_TIMEOUT,
                                   TEST_SEND_TIMEOUT,
                                   TEST_MAX_FRAME_SIZE);
        }
        catch (Throwable throwable) {
            if (isTimeoutException(throwable)) {
                return;
            }
            Throwables.propagate(throwable);
        }
        finally {
            client.close();
            serverSocket.close();
        }

        // Should never get here
        fail("Connection succeeded but failure was expected");
View Full Code Here

    public void testAsyncConnectTimeout() throws IOException
    {
        ServerSocket serverSocket = new ServerSocket(0);
        int port = serverSocket.getLocalPort();

        final NiftyClient client = new NiftyClient();
        try {
            ListenableFuture<FramedClientChannel> future =
                            client.connectAsync(new FramedClientConnector(new InetSocketAddress(port)),
                                                TEST_CONNECT_TIMEOUT,
                                                TEST_RECEIVE_TIMEOUT,
                                                TEST_READ_TIMEOUT,
                                                TEST_SEND_TIMEOUT,
                                                TEST_MAX_FRAME_SIZE);
            // Wait while NiftyClient attempts to connect the channel
            future.get();
        }
        catch (Throwable throwable) {
            if (isTimeoutException(throwable)) {
                return;
            }
            Throwables.propagate(throwable);
        }
        finally {
            client.close();
            serverSocket.close();
        }

        // Should never get here
        fail("Connection succeeded but failure was expected");
View Full Code Here

        this(new ThriftCodecManager());
    }

    public ThriftClientManager(ThriftCodecManager codecManager)
    {
        this(codecManager, new NiftyClient(), ImmutableSet.<ThriftClientEventHandler>of());
    }
View Full Code Here

    @Test(timeOut = 2000)
    public void testSyncConnectTimeout() throws ConnectException, IOException
    {
        ServerSocket serverSocket = new ServerSocket(0);
        int port = serverSocket.getLocalPort();
        final NiftyClient client = new NiftyClient();
        try {
                client.connectSync(new InetSocketAddress(port),
                                   TEST_CONNECT_TIMEOUT,
                                   TEST_READ_TIMEOUT,
                                   TEST_WRITE_TIMEOUT,
                                   TEST_MAX_FRAME_SIZE);
        }
        catch (Throwable throwable) {
            if (isTimeoutException(throwable)) {
                return;
            }
            Throwables.propagate(throwable);
        }
        finally {
            client.close();
            serverSocket.close();
        }

        // Should never get here
        fail("Connection succeeded but failure was expected");
View Full Code Here

    public void testAsyncConnectTimeout() throws IOException
    {
        ServerSocket serverSocket = new ServerSocket(0);
        int port = serverSocket.getLocalPort();

        final NiftyClient client = new NiftyClient();
        try {
            ListenableFuture<FramedClientChannel> future =
                            client.connectAsync(new FramedClientConnector(new InetSocketAddress(port)),
                                                TEST_CONNECT_TIMEOUT,
                                                TEST_READ_TIMEOUT,
                                                TEST_WRITE_TIMEOUT,
                                                TEST_MAX_FRAME_SIZE);
            // Wait while NiftyClient attempts to connect the channel
            future.get();
        }
        catch (Throwable throwable) {
            if (isTimeoutException(throwable)) {
                return;
            }
            Throwables.propagate(throwable);
        }
        finally {
            client.close();
            serverSocket.close();
        }

        // Should never get here
        fail("Connection succeeded but failure was expected");
View Full Code Here

TOP

Related Classes of com.facebook.nifty.client.NiftyClient

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.