Package org.elasticsearch.common.transport

Examples of org.elasticsearch.common.transport.InetSocketTransportAddress


            Discovery discovery = mock(Discovery.class);
            bind(Discovery.class).toInstance(discovery);
            when(discovery.localNode()).thenReturn(node);
            when(node.getId()).thenReturn("node-id-1");
            when(node.getName()).thenReturn("node 1");
            TransportAddress transportAddress = new InetSocketTransportAddress("localhost", 44300);
            when(node.address()).thenReturn(transportAddress);

            NetworkStats.Tcp tcp = mock(NetworkStats.Tcp.class, new Answer<Long>() {
                @Override
                public Long answer(InvocationOnMock invocation) throws Throwable {
                    return 42L;
                }
            });
            NetworkStats networkStats = mock(NetworkStats.class);
            when(networkStats.tcp()).thenReturn(tcp);
            NetworkService networkService = mock(NetworkService.class);
            when(networkService.stats()).thenReturn(networkStats);
            bind(NetworkService.class).toInstance(networkService);

            bind(NodeService.class).toInstance(nodeService);

            NodeEnvironment nodeEnv = mock(NodeEnvironment.class);
            File[] dataLocations = new File[]{ new File("/foo"), new File("/bar") };
            when(nodeEnv.hasNodeFile()).then(new Answer<Boolean>() {
                @Override
                public Boolean answer(InvocationOnMock invocation) throws Throwable {
                    return isDataNode;
                }
            });
            when(nodeEnv.nodeDataLocations()).thenReturn(dataLocations);
            bind(NodeEnvironment.class).toInstance(nodeEnv);

            Sigar sigar = mock(Sigar.class);
            SigarService sigarService = mock(SigarService.class);
            when(sigarService.sigarAvailable()).then(new Answer<Boolean>() {
                @Override
                public Boolean answer(InvocationOnMock invocation) throws Throwable {
                    return sigarAvailable;
                }
            });

            FileSystem fsFoo = mock(FileSystem.class);
            when(fsFoo.getDevName()).thenReturn("/dev/sda1");
            when(fsFoo.getDirName()).thenReturn("/foo");
            when(fsFoo.getType()).thenReturn(FileSystem.TYPE_LOCAL_DISK);

            FileSystem fsBar = mock(FileSystem.class);
            when(fsBar.getDevName()).thenReturn("/dev/sda2");
            when(fsBar.getDirName()).thenReturn("/bar");
            when(fsBar.getType()).thenReturn(FileSystem.TYPE_LOCAL_DISK);


            FileSystem fsFiltered = mock(FileSystem.class);
            when(fsFiltered.getType()).thenReturn(FileSystem.TYPE_UNKNOWN);
            when(fsFiltered.getDevName()).thenReturn(("/dev/filtered"));
            when(fsFiltered.getDirName()).thenReturn(("/filtered"));

            FileSystemMap map = mock(FileSystemMap.class);
            when(map.getMountPoint("/foo")).thenReturn(fsFoo);
            when(map.getMountPoint("/bar")).thenReturn(fsBar);
            when(map.getMountPoint("/filtered")).thenReturn(fsFiltered);
            FileSystemUsage usage = mock(FileSystemUsage.class, new Answer<Long>() {
                @Override
                public Long answer(InvocationOnMock invocation) throws Throwable {
                    return 42L;
                }
            });

            try {
                when(sigar.getFileSystemList()).thenReturn(new FileSystem[]{fsFoo, fsBar, fsFiltered});
                when(sigar.getFileSystemMap()).thenReturn(map);
                when(sigar.getFileSystemUsage(anyString())).thenReturn(usage);
                assertThat(sigar.getFileSystemUsage("/"), is(usage));
            } catch (SigarException e) {
                e.printStackTrace();
            }
            when(sigarService.sigar()).thenReturn(sigar);
            bind(SigarService.class).toInstance(sigarService);
            try {
                assertThat(sigarService.sigar().getFileSystemMap(), is(map));
            } catch (SigarException e) {
                e.printStackTrace();
            }

            HttpInfo httpInfo = mock(HttpInfo.class);
            when(nodeInfo.getHttp()).thenReturn(httpInfo);
            BoundTransportAddress boundTransportAddress = new BoundTransportAddress(
                    new InetSocketTransportAddress("localhost", 44200),
                    new InetSocketTransportAddress("localhost", 44200)
            );
            when(httpInfo.address()).thenReturn(boundTransportAddress);

            JvmService jvmService = mock(JvmService.class);
            JvmStats jvmStats = mock(JvmStats.class);
View Full Code Here


        try {
            publishAddress = new InetSocketAddress(networkService.resolvePublishHostAddress(publishHost), boundAddress.getPort());
        } catch (Exception e) {
            throw new BindTransportException("Failed to resolve publish address", e);
        }
        this.boundAddress = new BoundTransportAddress(new InetSocketTransportAddress(boundAddress), new InetSocketTransportAddress(publishAddress));
        final String httpAddress = "http://" + publishAddress.getAddress().getHostAddress() + ":" + publishAddress.getPort();

        discoveryNodeService.addCustomAttributeProvider(new DiscoveryNodeService.CustomAttributesProvider() {
            @Override
            public Map<String, String> buildAttributes() {
View Full Code Here

    int port = 9300;
    if (splitted.length > 1) {
      port = Integer.parseInt(splitted[1]);
    }
   
    return new InetSocketTransportAddress(splitted[0], port);
  }
View Full Code Here

    private void addAddress(SearchIntoContext context, String nodeAddress) {
        Matcher m = PATTERN.matcher(nodeAddress);
        if (m.matches()) {
            String host = m.group(1);
            int port = Integer.parseInt(m.group(2));
            InetSocketTransportAddress isa = new InetSocketTransportAddress(host, port);
            context.targetNodes().add(isa);
        } else {
            throw new InvalidNodeAddressException(context, nodeAddress);
        }
    }
View Full Code Here

                    .put("client.transport.ignore_cluster_name", false)
                    .put("node.client", true)
                    .put("client.transport.sniff", true)
                    .build();
            Client client = new TransportClient(settings)
                    .addTransportAddress(new InetSocketTransportAddress(config.getIp(), config.getPort()));
            this.client = client;
        } else {
            node = config.buildNode();
            client = node.client();
        }
View Full Code Here

        try {
            publishAddress = new InetSocketAddress(networkService.resolvePublishHostAddress(publishHost), boundAddress.getPort());
        } catch (Exception e) {
            throw new BindTransportException("Failed to resolve publish address", e);
        }
        this.boundAddress = new BoundTransportAddress(new InetSocketTransportAddress(boundAddress), new InetSocketTransportAddress(publishAddress));
    }
View Full Code Here

    @TestLogging("_root:DEBUG")
    public void testThatHttpPipeliningWorksWhenEnabled() throws Exception {
        Settings settings = settingsBuilder().put("http.pipelining", true).build();
        httpServerTransport = new CustomNettyHttpServerTransport(settings);
        httpServerTransport.start();
        InetSocketTransportAddress transportAddress = (InetSocketTransportAddress) httpServerTransport.boundAddress().boundAddress();

        List<String> requests = Arrays.asList("/firstfast", "/slow?sleep=500", "/secondfast", "/slow?sleep=1000", "/thirdfast");
        try (NettyHttpClient nettyHttpClient = new NettyHttpClient()) {
            Collection<HttpResponse> responses = nettyHttpClient.sendRequests(transportAddress.address(), requests.toArray(new String[]{}));
            Collection<String> responseBodies = returnHttpResponseBodies(responses);
            assertThat(responseBodies, contains("/firstfast", "/slow?sleep=500", "/secondfast", "/slow?sleep=1000", "/thirdfast"));
        }
    }
View Full Code Here

    @TestLogging("_root:TRACE")
    public void testThatHttpPipeliningCanBeDisabled() throws Exception {
        Settings settings = settingsBuilder().put("http.pipelining", false).build();
        httpServerTransport = new CustomNettyHttpServerTransport(settings);
        httpServerTransport.start();
        InetSocketTransportAddress transportAddress = (InetSocketTransportAddress) httpServerTransport.boundAddress().boundAddress();

        List<String> requests = Arrays.asList("/slow?sleep=1000", "/firstfast", "/secondfast", "/thirdfast", "/slow?sleep=500");
        try (NettyHttpClient nettyHttpClient = new NettyHttpClient()) {
            Collection<HttpResponse> responses = nettyHttpClient.sendRequests(transportAddress.address(), requests.toArray(new String[]{}));
            List<String> responseBodies = Lists.newArrayList(returnHttpResponseBodies(responses));
            // we cannot be sure about the order of the fast requests, but the slow ones should have to be last
            assertThat(responseBodies, hasSize(5));
            assertThat(responseBodies.get(3), is("/slow?sleep=500"));
            assertThat(responseBodies.get(4), is("/slow?sleep=1000"));
View Full Code Here

    @Test
    public void testThatNettyHttpServerSupportsPipelining() throws Exception {
        List<String> requests = Arrays.asList("/", "/_nodes/stats", "/", "/_cluster/state", "/");

        HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
        InetSocketTransportAddress inetSocketTransportAddress = (InetSocketTransportAddress) httpServerTransport.boundAddress().boundAddress();

        try (NettyHttpClient nettyHttpClient = new NettyHttpClient()) {
            Collection<HttpResponse> responses = nettyHttpClient.sendRequests(inetSocketTransportAddress.address(), requests.toArray(new String[]{}));
            assertThat(responses, hasSize(5));

            Collection<String> opaqueIds = returnOpaqueIds(responses);
            assertOpaqueIdsInOrder(opaqueIds);
        }
View Full Code Here

    public void testThatNettyHttpServerDoesNotSupportPipelining() throws Exception {
        ensureGreen();
        List<String> requests = Arrays.asList("/", "/_nodes/stats", "/", "/_cluster/state", "/", "/_nodes", "/");

        HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
        InetSocketTransportAddress inetSocketTransportAddress = (InetSocketTransportAddress) httpServerTransport.boundAddress().boundAddress();

        try (NettyHttpClient nettyHttpClient = new NettyHttpClient()) {
            Collection<HttpResponse> responses = nettyHttpClient.sendRequests(inetSocketTransportAddress.address(), requests.toArray(new String[]{}));
            assertThat(responses, hasSize(requests.size()));

            List<String> opaqueIds = Lists.newArrayList(returnOpaqueIds(responses));

            assertResponsesOutOfOrder(opaqueIds);
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.transport.InetSocketTransportAddress

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.