Search in sources :

Example 21 with ServerInfo

use of com.linkedin.databus.client.pub.ServerInfo in project databus by linkedin.

the class DummySuccessfulErrorCountingConsumer method testDispatcherRetriesExhausted.

@Test
public void testDispatcherRetriesExhausted() throws Exception {
    final Logger log = Logger.getLogger("TestDatabusHttpClient.testDispatcherRetriesExhausted");
    log.info("start");
    DatabusHttpClientImpl.Config clientConfig = new DatabusHttpClientImpl.Config();
    clientConfig.getConnectionDefaults().getPullerRetries().setMaxRetryNum(3);
    clientConfig.getConnectionDefaults().getDispatcherRetries().setMaxRetryNum(1);
    clientConfig.getContainer().getJmx().setRmiEnabled(false);
    int port = Utils.getAvailablePort(10100);
    clientConfig.getContainer().setHttpPort(0);
    final DatabusHttpClientImpl client = new DatabusHttpClientImpl(clientConfig);
    port = Utils.getAvailablePort(8898);
    @SuppressWarnings("unused") ServerInfo s1 = registerRelay(1, "relay1", new InetSocketAddress("localhost", port), "S1", client);
    //DummyStreamConsumer listener1 = new DummyStreamConsumer("consumer1");
    final DummySuccessfulErrorCountingConsumer listener1 = new DummySuccessfulErrorCountingConsumer("consumer1", true);
    client.registerDatabusStreamListener(listener1, null, "S1");
    Thread startThread = new Thread(new Runnable() {

        @Override
        public void run() {
            client.start();
        }
    }, "client start thread");
    startThread.start();
    TestUtil.assertWithBackoff(new ConditionCheck() {

        @Override
        public boolean check() {
            return client.getRelayConnections().size() == 1;
        }
    }, "client started", 1000, log);
    DatabusSourcesConnection dsc = client.getRelayConnections().get(0);
    RelayDispatcher rd = (RelayDispatcher) dsc.getRelayDispatcher();
    Assert.assertEquals(true, null != dsc);
    List<String> sources = new ArrayList<String>();
    Map<Long, IdNamePair> sourcesMap = new HashMap<Long, IdNamePair>();
    for (int i = 1; i <= 3; ++i) {
        IdNamePair sourcePair = new IdNamePair((long) i, "source" + i);
        sources.add(sourcePair.getName());
        sourcesMap.put(sourcePair.getId(), sourcePair);
    }
    HashMap<Long, List<RegisterResponseEntry>> schemaMap = new HashMap<Long, List<RegisterResponseEntry>>();
    List<RegisterResponseEntry> l1 = new ArrayList<RegisterResponseEntry>();
    List<RegisterResponseEntry> l2 = new ArrayList<RegisterResponseEntry>();
    List<RegisterResponseEntry> l3 = new ArrayList<RegisterResponseEntry>();
    final String SOURCE1_SCHEMA_STR = "{\"name\":\"source1\",\"type\":\"record\",\"fields\":[{\"name\":\"s\",\"type\":\"string\"}]}";
    final String SOURCE2_SCHEMA_STR = "{\"name\":\"source2\",\"type\":\"record\",\"fields\":[{\"name\":\"s\",\"type\":\"string\"}]}";
    ;
    final String SOURCE3_SCHEMA_STR = "{\"name\":\"source3\",\"type\":\"record\",\"fields\":[{\"name\":\"s\",\"type\":\"string\"}]}";
    ;
    l1.add(new RegisterResponseEntry(1L, (short) 1, SOURCE1_SCHEMA_STR));
    l2.add(new RegisterResponseEntry(2L, (short) 1, SOURCE2_SCHEMA_STR));
    l3.add(new RegisterResponseEntry(3L, (short) 1, SOURCE3_SCHEMA_STR));
    schemaMap.put(1L, l1);
    schemaMap.put(2L, l2);
    schemaMap.put(3L, l3);
    int source1EventsNum = 2;
    int source2EventsNum = 2;
    Hashtable<Long, AtomicInteger> keyCounts = new Hashtable<Long, AtomicInteger>();
    Hashtable<Short, AtomicInteger> srcidCounts = new Hashtable<Short, AtomicInteger>();
    // Send dummy e
    DbusEventBuffer eventsBuf = dsc.getDataEventsBuffer();
    eventsBuf.start(0);
    eventsBuf.startEvents();
    initBufferWithEvents(eventsBuf, 1, source1EventsNum, (short) 1, keyCounts, srcidCounts);
    initBufferWithEvents(eventsBuf, 1 + source1EventsNum, source2EventsNum, (short) 2, keyCounts, srcidCounts);
    eventsBuf.endEvents(100L, null);
    rd.enqueueMessage(SourcesMessage.createSetSourcesIdsMessage(sourcesMap.values()));
    rd.enqueueMessage(SourcesMessage.createSetSourcesSchemasMessage(schemaMap));
    TestUtil.assertWithBackoff(new ConditionCheck() {

        @Override
        public boolean check() {
            return listener1._errorCount == 1;
        }
    }, "error callback", 1000, log);
    client.shutdown();
    log.info("done");
}
Also used : HashMap(java.util.HashMap) ServerInfo(com.linkedin.databus.client.pub.ServerInfo) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) Logger(org.apache.log4j.Logger) IdNamePair(com.linkedin.databus.core.util.IdNamePair) List(java.util.List) ArrayList(java.util.ArrayList) ConditionCheck(com.linkedin.databus2.test.ConditionCheck) Hashtable(java.util.Hashtable) Checkpoint(com.linkedin.databus.core.Checkpoint) DbusEventBuffer(com.linkedin.databus.core.DbusEventBuffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RegisterResponseEntry(com.linkedin.databus2.core.container.request.RegisterResponseEntry) Test(org.testng.annotations.Test)

Example 22 with ServerInfo

use of com.linkedin.databus.client.pub.ServerInfo in project databus by linkedin.

the class TestClientChannelClose method testTimeoutCase.

@Test
public void testTimeoutCase() throws Exception {
    int port = Utils.getAvailablePort(27781);
    FakeRelay relay = new FakeRelay(port, 10, true, 100);
    TestClientConnectionFactory factory = null;
    try {
        relay.start();
        List<MsgState> msgList = new ArrayList<MsgState>();
        DatabusHttpClientImpl.Config conf = new DatabusHttpClientImpl.Config();
        conf.getContainer().setReadTimeoutMs(54);
        factory = new TestClientConnectionFactory(conf.build());
        ServerInfo relayInfo = new ServerInfo("dummy", "dummy", new InetSocketAddress(InetAddress.getLocalHost(), port), "dummy");
        for (int i = 0; i < 10; i++) {
            TestClientConnection conn = factory.createConnection(relayInfo, msgList);
            conn.requestCall();
            Thread.sleep(1000);
            System.out.println("MsgList is :" + msgList);
            //Assert.assertEquals(msgList.size(), 4, "Expected Size Check");
            int numMsgEnqueued = 0;
            for (MsgState s : msgList) {
                if (s == MsgState.MSG_ENQUEUED)
                    numMsgEnqueued++;
            }
            Assert.assertEquals(numMsgEnqueued, 1, "Expected NumEnqueued Msgs");
            msgList.clear();
        }
    } finally {
        if (null != relay)
            relay.shutdown();
        if (null != factory)
            factory.stop();
    }
}
Also used : ServerInfo(com.linkedin.databus.client.pub.ServerInfo) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) Test(org.testng.annotations.Test)

Example 23 with ServerInfo

use of com.linkedin.databus.client.pub.ServerInfo in project databus by linkedin.

the class TestDatabusV2ClusterRegistrationImpl method registerRelay.

private ServerInfo registerRelay(int id, String name, InetSocketAddress addr, String sources, DatabusHttpClientImpl client) throws InvalidConfigException {
    RuntimeConfigBuilder rtConfigBuilder = (RuntimeConfigBuilder) client.getClientConfigManager().getConfigBuilder();
    ServerInfoBuilder relayConfigBuilder = rtConfigBuilder.getRelay(Integer.toString(id));
    relayConfigBuilder.setName(name);
    relayConfigBuilder.setHost(addr.getHostName());
    relayConfigBuilder.setPort(addr.getPort());
    relayConfigBuilder.setSources(sources);
    ServerInfo si = relayConfigBuilder.build();
    client.getClientConfigManager().setNewConfig(rtConfigBuilder.build());
    return si;
}
Also used : ServerInfo(com.linkedin.databus.client.pub.ServerInfo) RuntimeConfigBuilder(com.linkedin.databus.client.DatabusHttpClientImpl.RuntimeConfigBuilder) ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder)

Example 24 with ServerInfo

use of com.linkedin.databus.client.pub.ServerInfo in project databus by linkedin.

the class TestDatabusV2RegistrationImpl method registerRelay.

private ServerInfo registerRelay(int id, String name, InetSocketAddress addr, String sources, DatabusHttpClientImpl client) throws InvalidConfigException {
    RuntimeConfigBuilder rtConfigBuilder = (RuntimeConfigBuilder) client.getClientConfigManager().getConfigBuilder();
    ServerInfoBuilder relayConfigBuilder = rtConfigBuilder.getRelay(Integer.toString(id));
    relayConfigBuilder.setName(name);
    relayConfigBuilder.setHost(addr.getHostName());
    relayConfigBuilder.setPort(addr.getPort());
    relayConfigBuilder.setSources(sources);
    ServerInfo si = relayConfigBuilder.build();
    client.getClientConfigManager().setNewConfig(rtConfigBuilder.build());
    return si;
}
Also used : ServerInfo(com.linkedin.databus.client.pub.ServerInfo) RuntimeConfigBuilder(com.linkedin.databus.client.DatabusHttpClientImpl.RuntimeConfigBuilder) ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder)

Example 25 with ServerInfo

use of com.linkedin.databus.client.pub.ServerInfo in project databus by linkedin.

the class RelayEventProducer method createServerInfo.

static Set<ServerInfo> createServerInfo(String serverName, String subscriptions) throws InvalidConfigException {
    Set<ServerInfo> serverInfo = new HashSet<ServerInfo>();
    ServerInfoBuilder sBuilder = new ServerInfoBuilder();
    sBuilder.setAddress(serverName + ":" + subscriptions);
    // sBuilder.setSources(subscriptions);
    serverInfo.add(sBuilder.build());
    return serverInfo;
}
Also used : ServerInfo(com.linkedin.databus.client.pub.ServerInfo) HashSet(java.util.HashSet) ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder)

Aggregations

ServerInfo (com.linkedin.databus.client.pub.ServerInfo)44 Checkpoint (com.linkedin.databus.core.Checkpoint)23 ArrayList (java.util.ArrayList)21 Test (org.testng.annotations.Test)19 HashMap (java.util.HashMap)16 List (java.util.List)16 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)15 IdNamePair (com.linkedin.databus.core.util.IdNamePair)14 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)10 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)10 InetSocketAddress (java.net.InetSocketAddress)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 HashSet (java.util.HashSet)6 RemoteExceptionHandler (com.linkedin.databus.client.netty.RemoteExceptionHandler)5 DatabusClientException (com.linkedin.databus.client.pub.DatabusClientException)5 ServerInfoBuilder (com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder)5 DbusKeyCompositeFilterConfig (com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig)5 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)5 Properties (java.util.Properties)5 Logger (org.apache.log4j.Logger)5