@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); } }
public void onEvent(ReplicaId replicaId, Object event) { if (event instanceof ServerErrorCode) { onServerEvent(replicaId, (ServerErrorCode) event); } else if (event instanceof Exception) { onException(replicaId, (Exception) event); } else if (event instanceof NetworkClientErrorCode) { onNetworkEvent(replicaId, (NetworkClientErrorCode) event); } }
ResponseHandler { public void onEvent(ReplicaId replicaId, Object event) { if (event instanceof ServerErrorCode) { onServerEvent(replicaId, (ServerErrorCode) event); } else if (event instanceof Exception) { onException(replicaId, (Exception) event); } else if (event instanceof NetworkClientErrorCode) { onNetworkEvent(replicaId, (NetworkClientErrorCode) event); } } }
ResponseHandler { public void onEvent(ReplicaId replicaId, Object event) { if (event instanceof ServerErrorCode) { onServerEvent(replicaId, (ServerErrorCode) event); } else if (event instanceof Exception) { onException(replicaId, (Exception) event); } else if (event instanceof NetworkClientErrorCode) { onNetworkEvent(replicaId, (NetworkClientErrorCode) event); } } ResponseHandler(ClusterMap clusterMap); }
ResponseHandler { public void onEvent(ReplicaId replicaId, Object event) { if (event instanceof ServerErrorCode) { onServerEvent(replicaId, (ServerErrorCode) event); } else if (event instanceof Exception) { onException(replicaId, (Exception) event); } else if (event instanceof NetworkClientErrorCode) { onNetworkEvent(replicaId, (NetworkClientErrorCode) event); } } ResponseHandler(ClusterMap clusterMap); void onEvent(ReplicaId replicaId, Object event); void onConnectionTimeout(DataNodeId dataNodeId); }
ResponseHandler { public void onEvent(ReplicaId replicaId, Object event) { if (event instanceof ServerErrorCode) { onServerEvent(replicaId, (ServerErrorCode) event); } else if (event instanceof Exception) { onException(replicaId, (Exception) event); } else if (event instanceof NetworkClientErrorCode) { onNetworkEvent(replicaId, (NetworkClientErrorCode) event); } } ResponseHandler(ClusterMap clusterMap); void onEvent(ReplicaId replicaId, Object event); void onConnectionTimeout(DataNodeId dataNodeId);  }