Search in sources :

Example 11 with Server

use of org.apache.druid.client.selector.Server in project druid by druid-io.

the class ServerDiscoverySelectorTest method testPick.

@Test
public void testPick() throws Exception {
    EasyMock.expect(serviceProvider.getInstance()).andReturn(instance).anyTimes();
    EasyMock.expect(instance.getAddress()).andReturn(ADDRESS).anyTimes();
    EasyMock.expect(instance.getPort()).andReturn(PORT).anyTimes();
    EasyMock.expect(instance.getSslPort()).andReturn(-1).anyTimes();
    EasyMock.replay(instance, serviceProvider);
    Server server = serverDiscoverySelector.pick();
    Assert.assertEquals(PORT, server.getPort());
    Assert.assertEquals(ADDRESS, server.getAddress());
    Assert.assertTrue(server.getHost().contains(Integer.toString(PORT)));
    Assert.assertTrue(server.getHost().contains(ADDRESS));
    Assert.assertEquals("http", server.getScheme());
    EasyMock.verify(instance, serviceProvider);
    final URI uri = new URI(server.getScheme(), null, server.getAddress(), server.getPort(), "/druid/indexer/v1/action", null, null);
    Assert.assertEquals(PORT, uri.getPort());
    Assert.assertEquals(ADDRESS, uri.getHost());
    Assert.assertEquals("http", uri.getScheme());
}
Also used : Server(org.apache.druid.client.selector.Server) URI(java.net.URI) Test(org.junit.Test)

Example 12 with Server

use of org.apache.druid.client.selector.Server in project druid by druid-io.

the class ServerDiscoverySelectorTest method testPickWithNullSslPort.

@Test
public void testPickWithNullSslPort() throws Exception {
    EasyMock.expect(serviceProvider.getInstance()).andReturn(instance).anyTimes();
    EasyMock.expect(instance.getAddress()).andReturn(ADDRESS).anyTimes();
    EasyMock.expect(instance.getPort()).andReturn(PORT).anyTimes();
    EasyMock.expect(instance.getSslPort()).andReturn(null).anyTimes();
    EasyMock.replay(instance, serviceProvider);
    Server server = serverDiscoverySelector.pick();
    Assert.assertEquals(PORT, server.getPort());
    Assert.assertEquals(ADDRESS, server.getAddress());
    Assert.assertTrue(server.getHost().contains(Integer.toString(PORT)));
    Assert.assertTrue(server.getHost().contains(ADDRESS));
    Assert.assertEquals("http", server.getScheme());
    EasyMock.verify(instance, serviceProvider);
    final URI uri = new URI(server.getScheme(), null, server.getAddress(), server.getPort(), "/druid/indexer/v1/action", null, null);
    Assert.assertEquals(PORT, uri.getPort());
    Assert.assertEquals(ADDRESS, uri.getHost());
    Assert.assertEquals("http", uri.getScheme());
}
Also used : Server(org.apache.druid.client.selector.Server) URI(java.net.URI) Test(org.junit.Test)

Example 13 with Server

use of org.apache.druid.client.selector.Server in project druid by druid-io.

the class ServerDiscoverySelectorTest method testPickWithException.

@Test
public void testPickWithException() throws Exception {
    EasyMock.expect(serviceProvider.getInstance()).andThrow(new Exception()).anyTimes();
    EasyMock.replay(serviceProvider);
    Server server = serverDiscoverySelector.pick();
    Assert.assertNull(server);
    EasyMock.verify(serviceProvider);
}
Also used : Server(org.apache.druid.client.selector.Server) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with Server

use of org.apache.druid.client.selector.Server in project druid by druid-io.

the class ConsistentHashAvaticaConnectionBalancer method pickServer.

@Override
public Server pickServer(Collection<Server> servers, String connectionId) {
    synchronized (hasher) {
        if (servers.isEmpty()) {
            return null;
        }
        Map<String, Server> serverMap = new HashMap<>();
        for (Server server : servers) {
            serverMap.put(server.getHost(), server);
        }
        hasher.updateKeys(serverMap.keySet());
        String chosenServer = hasher.findKey(StringUtils.toUtf8(connectionId));
        return serverMap.get(chosenServer);
    }
}
Also used : Server(org.apache.druid.client.selector.Server) HashMap(java.util.HashMap)

Example 15 with Server

use of org.apache.druid.client.selector.Server in project druid by druid-io.

the class QueryHostFinder method findServerSql.

public Server findServerSql(SqlQuery sqlQuery) {
    Server server = findServerInner(hostSelector.selectForSql(sqlQuery));
    assertServerFound(server, "No server found for SQL Query [%s]", "SELECT IT");
    return server;
}
Also used : Server(org.apache.druid.client.selector.Server)

Aggregations

Server (org.apache.druid.client.selector.Server)20 Test (org.junit.Test)10 URI (java.net.URI)5 IOException (java.io.IOException)3 Query (org.apache.druid.query.Query)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ServletException (javax.servlet.ServletException)2 Service (org.apache.calcite.avatica.remote.Service)2 DruidServer (org.apache.druid.client.DruidServer)2 QueryInterruptedException (org.apache.druid.query.QueryInterruptedException)2 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)2 SqlQuery (org.apache.druid.sql.http.SqlQuery)2 SmileMediaTypes (com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1