Search in sources :

Example 11 with ServerInfo

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

the class DummySuccessfulErrorCountingConsumer 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 12 with ServerInfo

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

the class DummySuccessfulErrorCountingConsumer method testPullerRetriesExhausted.

@Test
public void testPullerRetriesExhausted() throws Exception {
    final Logger log = Logger.getLogger("TestDatabusHttpClient.testPullerRetriesExhausted");
    log.info("start");
    DatabusHttpClientImpl.Config clientConfig = new DatabusHttpClientImpl.Config();
    clientConfig.getConnectionDefaults().getPullerRetries().setMaxRetryNum(1);
    clientConfig.getContainer().getJmx().setRmiEnabled(false);
    clientConfig.getContainer().setHttpPort(10100);
    final DatabusHttpClientImpl client = new DatabusHttpClientImpl(clientConfig);
    int port = Utils.getAvailablePort(8888);
    @SuppressWarnings("unused") ServerInfo s1 = registerRelay(1, "relay1", new InetSocketAddress("localhost", port), "S1", client);
    final DummySuccessfulErrorCountingConsumer listener1 = new DummySuccessfulErrorCountingConsumer("consumer1", false);
    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;
        }
    }, "waiting for client to start", 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);
    rd.enqueueMessage(SourcesMessage.createSetSourcesIdsMessage(sourcesMap.values()));
    rd.enqueueMessage(SourcesMessage.createSetSourcesSchemasMessage(schemaMap));
    TestUtil.assertWithBackoff(new ConditionCheck() {

        @Override
        public boolean check() {
            return listener1._errorCount == 1;
        }
    }, "wait for error", 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) Checkpoint(com.linkedin.databus.core.Checkpoint) RegisterResponseEntry(com.linkedin.databus2.core.container.request.RegisterResponseEntry) Test(org.testng.annotations.Test)

Example 13 with ServerInfo

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

the class MockBootstrapConnection method createSetServerMessage.

private ServerSetChangeMessage createSetServerMessage(boolean keepCurrent, BasePullThread puller) {
    Set<ServerInfo> serverInfoSet = new HashSet<ServerInfo>();
    InetSocketAddress inetAddr1 = new InetSocketAddress("localhost", 10000);
    ServerInfo s = new ServerInfo("newBs1", "ONLINE", inetAddr1, Arrays.asList("source1"));
    serverInfoSet.add(s);
    if (keepCurrent) {
        serverInfoSet.addAll(puller.getServers());
    }
    ServerSetChangeMessage msg = ServerSetChangeMessage.createSetServersMessage(serverInfoSet);
    return msg;
}
Also used : ServerInfo(com.linkedin.databus.client.pub.ServerInfo) InetSocketAddress(java.net.InetSocketAddress) HashSet(java.util.HashSet)

Example 14 with ServerInfo

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

the class MockBootstrapConnection method testServerSetChange_StreamResponseSuccess.

@Test
public /** Test ServerSet change when in Stream_Response_Success state */
void testServerSetChange_StreamResponseSuccess() throws Exception {
    BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, 12000, 1);
    Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 0L);
    //TODO remove
    //    cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
    //    cp.setSnapshotSource("source1");
    //    cp.setCatchupSource("source1");
    bsPuller.getComponentStatus().start();
    ConnectionState connState = bsPuller.getConnectionState();
    connState.switchToBootstrap(cp);
    testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_START_SCN, cp);
    bsPuller.getMessageQueue().clear();
    testTransitionCase(bsPuller, StateId.REQUEST_START_SCN, StateId.START_SCN_RESPONSE_SUCCESS, null);
    bsPuller.getMessageQueue().clear();
    Map<Long, List<RegisterResponseEntry>> entries = new HashMap<Long, List<RegisterResponseEntry>>();
    entries.put(1L, new ArrayList<RegisterResponseEntry>());
    connState.setSourcesSchemas(entries);
    connState.setCurrentBSServerInfo(bsPuller.getCurentServer());
    testTransitionCase(bsPuller, StateId.START_SCN_RESPONSE_SUCCESS, StateId.REQUEST_STREAM, null);
    bsPuller.getMessageQueue().clear();
    connState.getSourcesNameMap().put("source1", new IdNamePair(1L, "source1"));
    connState.getSourceIdMap().put(1L, new IdNamePair(1L, "source1"));
    testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS, null);
    // ServerSetChange when New Set includes CurrentServer
    {
        Assert.assertEquals(bsPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
        Assert.assertEquals(bsPuller.getCurentServer() != null, true, "Current Server not Null");
        ServerInfo oldServer = bsPuller.getCurentServer();
        Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_1, "Server Set");
        entries = new HashMap<Long, List<RegisterResponseEntry>>();
        entries.put(1L, new ArrayList<RegisterResponseEntry>());
        connState.setSourcesSchemas(entries);
        doExecuteAndChangeState(bsPuller, createSetServerMessage(true, bsPuller));
        Assert.assertEquals(bsPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
        Assert.assertEquals(bsPuller.getCurentServer(), oldServer, "Current Server unchanged");
        Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_2, "Server Set");
        Assert.assertEquals(bsPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
        Assert.assertEquals(connState.getStateId(), StateId.STREAM_REQUEST_SUCCESS, "ServerSetChange while STREAM_REQUEST_SUCCESS");
        Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: [STREAM_REQUEST_SUCCESS]", "Queue :ServerSetChange while STREAM_REQUEST_SUCCESS");
    }
    // ServerSetChange when New Set excludes CurrentServer and SuccessFul Response
    {
        int oldServerIndex = bsPuller.getCurrentServerIdx();
        ServerInfo oldServer = bsPuller.getCurentServer();
        Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_2, "Server Set");
        entries = new HashMap<Long, List<RegisterResponseEntry>>();
        entries.put(1L, new ArrayList<RegisterResponseEntry>());
        connState.setSourcesSchemas(entries);
        doExecuteAndChangeState(bsPuller, createSetServerMessage(false, bsPuller));
        Assert.assertEquals(bsPuller.getCurrentServerIdx(), oldServerIndex, "Current Server Index unchanged");
        Assert.assertEquals(bsPuller.getCurentServer(), oldServer, "Current Server unchanged");
        Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_3, "Server Set");
        Assert.assertEquals(bsPuller.toTearConnAfterHandlingResponse(), true, "Tear Conn After Handling Response");
        Assert.assertEquals(connState.getStateId(), StateId.STREAM_REQUEST_SUCCESS, "ServerSetChange while STREAM_REQUEST_SUCCESS");
        Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: [STREAM_REQUEST_SUCCESS]", "Queue :ServerSetChange while STREAM_REQUEST_SUCCESS");
        // Now Response arrives
        connState.switchToStartScnSuccess(cp, null, null);
        testTransitionCase(bsPuller, StateId.START_SCN_REQUEST_SENT, StateId.PICK_SERVER, null);
        Assert.assertEquals(bsPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
        Assert.assertEquals(bsPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
        Assert.assertEquals(bsPuller.getCurentServer() == null, true, "Current Server Null");
    }
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint) HashMap(java.util.HashMap) ServerInfo(com.linkedin.databus.client.pub.ServerInfo) RegisterResponseEntry(com.linkedin.databus2.core.container.request.RegisterResponseEntry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IdNamePair(com.linkedin.databus.core.util.IdNamePair) Test(org.testng.annotations.Test)

Example 15 with ServerInfo

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

the class MockBootstrapConnection method testServerSetChange_RequestTargetScn.

@Test
public /** Test ServerSet change when in Request_target_Scn state */
void testServerSetChange_RequestTargetScn() throws Exception {
    BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, false, false, null, 12000, 1, true);
    Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 0L);
    bsPuller.getComponentStatus().start();
    ConnectionState connState = bsPuller.getConnectionState();
    connState.switchToBootstrap(cp);
    testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_START_SCN, cp);
    bsPuller.getMessageQueue().clear();
    testTransitionCase(bsPuller, StateId.REQUEST_START_SCN, StateId.START_SCN_RESPONSE_SUCCESS, null);
    bsPuller.getMessageQueue().clear();
    Map<Long, List<RegisterResponseEntry>> entries = new HashMap<Long, List<RegisterResponseEntry>>();
    entries.put(1L, new ArrayList<RegisterResponseEntry>());
    connState.setSourcesSchemas(entries);
    connState.setCurrentBSServerInfo(bsPuller.getCurentServer());
    testTransitionCase(bsPuller, StateId.START_SCN_RESPONSE_SUCCESS, StateId.REQUEST_STREAM, null);
    bsPuller.getMessageQueue().clear();
    connState.getSourcesNameMap().put("source1", new IdNamePair(1L, "source1"));
    connState.getSourceIdMap().put(1L, new IdNamePair(1L, "source1"));
    testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS, null);
    bsPuller.getMessageQueue().clear();
    testTransitionCase(bsPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE, null);
    bsPuller.getMessageQueue().clear();
    cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
    cp.setSnapshotOffset(-1);
    //cp.setBootstrapStartScn(100L);
    testTransitionCase(bsPuller, StateId.STREAM_RESPONSE_DONE, StateId.REQUEST_TARGET_SCN, null);
    //Assert.assertEquals(cp.getWindowScn(), 100L, "WindowSCN Check");
    //Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_CATCHUP, "Consumption Mode check");
    Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_SNAPSHOT, "Consumption Mode check");
    Assert.assertEquals(cp.getCatchupSource(), "source1", "Catchup Source check");
    // ServerSetChange when New Set includes CurrentServer
    {
        Assert.assertEquals(bsPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
        Assert.assertEquals(bsPuller.getCurentServer() != null, true, "Current Server not Null");
        ServerInfo oldServer = bsPuller.getCurentServer();
        Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_1, "Server Set");
        doExecuteAndChangeState(bsPuller, createSetServerMessage(true, bsPuller));
        Assert.assertEquals(bsPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
        Assert.assertEquals(bsPuller.getCurentServer(), oldServer, "Current Server unchanged");
        Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_2, "Server Set");
        Assert.assertEquals(bsPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
        Assert.assertEquals(connState.getStateId(), StateId.REQUEST_TARGET_SCN, "ServerSetChange while REQUEST_TARGET_SCN");
        Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: [REQUEST_TARGET_SCN]", "Queue :ServerSetChange while REQUEST_TARGET_SCN");
    }
    // ServerSetChange when New Set excludes CurrentServer
    {
        Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_2, "Server Set");
        doExecuteAndChangeState(bsPuller, createSetServerMessage(false, bsPuller));
        Assert.assertEquals(bsPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
        Assert.assertEquals(bsPuller.getCurentServer() == null, true, "Current Server Null");
        Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_3, "Server Set");
        Assert.assertEquals(bsPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
        Assert.assertEquals(connState.getStateId(), StateId.PICK_SERVER, "ServerSetChange while REQUEST_TARGET_SCN");
        Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: [PICK_SERVER]", "Queue :ServerSetChange while REQUEST_TARGET_SCN");
    }
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint) HashMap(java.util.HashMap) ServerInfo(com.linkedin.databus.client.pub.ServerInfo) RegisterResponseEntry(com.linkedin.databus2.core.container.request.RegisterResponseEntry) ArrayList(java.util.ArrayList) List(java.util.List) IdNamePair(com.linkedin.databus.core.util.IdNamePair) Test(org.testng.annotations.Test)

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