Search in sources :

Example 36 with ServerInfo

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

the class MockBootstrapConnection method testServerSetChange_StreamRequestSent.

@Test
public /** Tests ServerSet change when in Stream_Request_Sent */
void testServerSetChange_StreamRequestSent() 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"));
    MockBootstrapConnection mockConn = (MockBootstrapConnection) connState.getBootstrapConnection();
    mockConn.setMuteTransition(true);
    testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SENT, "", 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_SENT, "ServerSetChange while STREAM_REQUEST_SENT");
        Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while STREAM_REQUEST_SENT");
    }
    // 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_SENT, "ServerSetChange while STREAM_REQUEST_SENT");
        Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while STREAM_REQUEST_SENT");
        // 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 : HashMap(java.util.HashMap) ServerInfo(com.linkedin.databus.client.pub.ServerInfo) ArrayList(java.util.ArrayList) Checkpoint(com.linkedin.databus.core.Checkpoint) 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)

Example 37 with ServerInfo

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

the class MockBootstrapConnection method testServerSetChange_RequestStream.

@Test
public /** Test ServerSet Change when in Request_stream state */
void testServerSetChange_RequestStream() throws Exception {
    BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false);
    Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 1L);
    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);
    // 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_STREAM, "ServerSetChange while REQUEST_STREAM");
        Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: [REQUEST_STREAM]", "Queue :ServerSetChange while REQUEST_STREAM");
    }
    // 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_STREAM");
        Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: [PICK_SERVER]", "Queue :ServerSetChange while REQUEST_STREAM");
    }
}
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) Test(org.testng.annotations.Test)

Example 38 with ServerInfo

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

the class MockBootstrapConnection method testServerSetChange_TargetScnResponseSuccess.

@Test
public /** Test ServerSet change when in Target_Scn_Response_ Success state */
void testServerSetChange_TargetScnResponseSuccess() throws Exception {
    BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, false, false, null, 12000, 1, true);
    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);
    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);
    testTransitionCase(bsPuller, StateId.STREAM_RESPONSE_DONE, StateId.REQUEST_TARGET_SCN, null);
    Assert.assertTrue(cp.isSnapShotSourceCompleted(), "Phase completed");
    Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_SNAPSHOT, "Consumption Mode check");
    Assert.assertFalse(cp.isBootstrapTargetScnSet());
    bsPuller.getMessageQueue().clear();
    testTransitionCase(bsPuller, StateId.REQUEST_TARGET_SCN, StateId.TARGET_SCN_RESPONSE_SUCCESS, null);
    Assert.assertTrue(cp.isBootstrapTargetScnSet());
    Assert.assertEquals(cp.getBootstrapTargetScn().longValue(), 10L);
    // 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.TARGET_SCN_RESPONSE_SUCCESS, "ServerSetChange while TARGET_SCN_RESPONSE_SUCCESS");
        Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: [TARGET_SCN_RESPONSE_SUCCESS]", "Queue :ServerSetChange while TARGET_SCN_RESPONSE_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.TARGET_SCN_RESPONSE_SUCCESS, "ServerSetChange while TARGET_SCN_RESPONSE_SUCCESS");
        Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: [TARGET_SCN_RESPONSE_SUCCESS]", "Queue :ServerSetChange while TARGET_SCN_RESPONSE_SUCCESS");
        // Now Response arrives
        connState.switchToStartScnSuccess(cp, null, null);
        testTransitionCase(bsPuller, StateId.TARGET_SCN_RESPONSE_SUCCESS, 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 39 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)

Example 40 with ServerInfo

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

the class DatabusHttpClientImpl method getRandomRelay.

/**
   *
   * @throws DatabusClientException
   */
protected ServerInfo getRandomRelay(Map<List<DatabusSubscription>, Set<ServerInfo>> groupsServers, List<DatabusSubscription> sources) throws DatabusClientException {
    List<ServerInfo> candidateServers = findServers(groupsServers, sources);
    if (0 == candidateServers.size()) {
        throw new DatabusClientException("Unable to find servers to support sources: " + sources);
    }
    Random rng = new Random();
    ServerInfo randomRelay = candidateServers.get(rng.nextInt(candidateServers.size()));
    return randomRelay;
}
Also used : Random(java.util.Random) ServerInfo(com.linkedin.databus.client.pub.ServerInfo) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException)

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