Search in sources :

Example 1 with ReplicaEventType

use of com.github.ambry.clustermap.ReplicaEventType in project ambry by linkedin.

the class ResponseHandlerTest method basicTest.

@Test
public void basicTest() {
    DummyMap mockClusterMap = new DummyMap();
    ResponseHandler handler = new ResponseHandler(mockClusterMap);
    Map<Object, ReplicaEventType[]> expectedEventTypes = new HashMap<>();
    expectedEventTypes.put(new SocketException(), new ReplicaEventType[] { ReplicaEventType.Node_Timeout });
    expectedEventTypes.put(new IOException(), new ReplicaEventType[] { ReplicaEventType.Node_Timeout });
    expectedEventTypes.put(new ConnectionPoolTimeoutException(""), new ReplicaEventType[] { ReplicaEventType.Node_Timeout });
    expectedEventTypes.put(ServerErrorCode.IO_Error, new ReplicaEventType[] { ReplicaEventType.Node_Response, ReplicaEventType.Disk_Error });
    expectedEventTypes.put(ServerErrorCode.Disk_Unavailable, new ReplicaEventType[] { ReplicaEventType.Node_Response, ReplicaEventType.Disk_Error });
    expectedEventTypes.put(ServerErrorCode.Partition_ReadOnly, new ReplicaEventType[] { ReplicaEventType.Node_Response, ReplicaEventType.Disk_Ok, ReplicaEventType.Partition_ReadOnly, ReplicaEventType.Replica_Available });
    expectedEventTypes.put(ServerErrorCode.Replica_Unavailable, new ReplicaEventType[] { ReplicaEventType.Node_Response, ReplicaEventType.Disk_Ok, ReplicaEventType.Replica_Unavailable });
    expectedEventTypes.put(ServerErrorCode.Temporarily_Disabled, new ReplicaEventType[] { ReplicaEventType.Node_Response, ReplicaEventType.Disk_Ok, ReplicaEventType.Replica_Unavailable });
    expectedEventTypes.put(ServerErrorCode.Unknown_Error, new ReplicaEventType[] { ReplicaEventType.Node_Response, ReplicaEventType.Disk_Ok, ReplicaEventType.Replica_Available });
    expectedEventTypes.put(ServerErrorCode.No_Error, new ReplicaEventType[] { ReplicaEventType.Node_Response, ReplicaEventType.Disk_Ok, ReplicaEventType.Replica_Available });
    expectedEventTypes.put(NetworkClientErrorCode.NetworkError, new ReplicaEventType[] { ReplicaEventType.Node_Timeout });
    expectedEventTypes.put(NetworkClientErrorCode.ConnectionUnavailable, new ReplicaEventType[] {});
    expectedEventTypes.put(new RouterException("", RouterErrorCode.UnexpectedInternalError), new ReplicaEventType[] {});
    expectedEventTypes.put(RouterErrorCode.AmbryUnavailable, new ReplicaEventType[] {});
    for (Map.Entry<Object, ReplicaEventType[]> entry : expectedEventTypes.entrySet()) {
        mockClusterMap.reset();
        handler.onEvent(new MockReplicaId(ReplicaType.DISK_BACKED), entry.getKey());
        Set<ReplicaEventType> expectedEvents = new HashSet<>(Arrays.asList(entry.getValue()));
        Set<ReplicaEventType> generatedEvents = mockClusterMap.getLastReplicaEvents();
        Assert.assertEquals("Unexpected generated event for event " + entry.getKey() + " \nExpected: " + expectedEvents + " \nReceived: " + generatedEvents, expectedEvents, generatedEvents);
    }
}
Also used : SocketException(java.net.SocketException) RouterException(com.github.ambry.router.RouterException) HashMap(java.util.HashMap) IOException(java.io.IOException) ConnectionPoolTimeoutException(com.github.ambry.network.ConnectionPoolTimeoutException) ReplicaEventType(com.github.ambry.clustermap.ReplicaEventType) MockReplicaId(com.github.ambry.clustermap.MockReplicaId) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) ClusterMap(com.github.ambry.clustermap.ClusterMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ClusterMap (com.github.ambry.clustermap.ClusterMap)1 MockReplicaId (com.github.ambry.clustermap.MockReplicaId)1 ReplicaEventType (com.github.ambry.clustermap.ReplicaEventType)1 ConnectionPoolTimeoutException (com.github.ambry.network.ConnectionPoolTimeoutException)1 RouterException (com.github.ambry.router.RouterException)1 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1