@Test public void testPartitions() throws Exception { StorageManager storageManager = Mockito.mock(StorageManager.class); StorageServerHandler storageServerHandler = Mockito.spy(new StorageServerHandler(storageManager)); ArgumentCaptor<FailureResponse> msgArg = ArgumentCaptor.forClass(FailureResponse.class); ArgumentCaptor<Boolean> boolArg = ArgumentCaptor.forClass(Boolean.class); int partitionId = new Random().nextInt(NUM_PARTITION); AppendRequest msg = new AppendRequest(-1, -1, partitionId, null); storageServerHandler.process(msg); Mockito.verify(storageServerHandler).sendMessage(msgArg.capture(), boolArg.capture()); assertTrue(msgArg.getValue().exception.toString().contains("Partition:" + partitionId + " is not assigned.")); }
@Override protected void process(Message msg) throws Exception { StorageMessage message = (StorageMessage) msg; switch (message.type()) { case StorageMessageType.OPEN_REQUEST: try { storageManager.open(((OpenRequest) message).key, ((OpenRequest) message).numPartitions); success(); } catch (IllegalArgumentException ex) { failure(new StorageException("wrong key format")); } catch (StorageException ex) { failure(ex); } break; default: Partition partition = storageManager.getPartition(((StorageMessage) msg).partitionId); if (partition != null) { partition.receiveMessage(msg, this); } else { failure(new Exception("Partition:" + message.partitionId + " is not assigned."), message); } } }
StorageServerHandler extends MessageHandler implements PartitionClient { @Override protected void process(Message msg) throws Exception { StorageMessage message = (StorageMessage) msg; switch (message.type()) { case StorageMessageType.OPEN_REQUEST: try { storageManager.open(((OpenRequest) message).key, ((OpenRequest) message).numPartitions); success(); } catch (IllegalArgumentException ex) { failure(new StorageException("wrong key format")); } catch (StorageException ex) { failure(ex); } break; default: Partition partition = storageManager.getPartition(((StorageMessage) msg).partitionId); if (partition != null) { partition.receiveMessage(msg, this); } else { failure(new Exception("Partition:" + message.partitionId + " is not assigned."), message); } } } }
StorageServerHandler extends MessageHandler implements PartitionClient { @Override protected void process(Message msg) throws Exception { StorageMessage message = (StorageMessage) msg; switch (message.type()) { case StorageMessageType.OPEN_REQUEST: try { storageManager.open(((OpenRequest) message).key, ((OpenRequest) message).numPartitions); success(); } catch (IllegalArgumentException ex) { failure(new StorageException("wrong key format")); } catch (StorageException ex) { failure(ex); } break; default: Partition partition = storageManager.getPartition(((StorageMessage) msg).partitionId); if (partition != null) { partition.receiveMessage(msg, this); } else { failure(new Exception("Partition:" + message.partitionId + " is not assigned."), message); } } } StorageServerHandler(StorageManager storageManager); }
StorageServerHandler extends MessageHandler implements PartitionClient { @Override protected void process(Message msg) throws Exception { StorageMessage message = (StorageMessage) msg; switch (message.type()) { case StorageMessageType.OPEN_REQUEST: try { storageManager.open(((OpenRequest) message).key, ((OpenRequest) message).numPartitions); success(); } catch (IllegalArgumentException ex) { failure(new StorageException("wrong key format")); } catch (StorageException ex) { failure(ex); } break; default: Partition partition = storageManager.getPartition(((StorageMessage) msg).partitionId); if (partition != null) { partition.receiveMessage(msg, this); } else { failure(new Exception("Partition:" + message.partitionId + " is not assigned."), message); } } } StorageServerHandler(StorageManager storageManager);  }
StorageServerHandler extends MessageHandler implements PartitionClient { @Override protected void process(Message msg) throws Exception { StorageMessage message = (StorageMessage) msg; switch (message.type()) { case StorageMessageType.OPEN_REQUEST: try { storageManager.open(((OpenRequest) message).key, ((OpenRequest) message).numPartitions); success(); } catch (IllegalArgumentException ex) { failure(new StorageException("wrong key format")); } catch (StorageException ex) { failure(ex); } break; default: Partition partition = storageManager.getPartition(((StorageMessage) msg).partitionId); if (partition != null) { partition.receiveMessage(msg, this); } else { failure(new Exception("Partition:" + message.partitionId + " is not assigned."), message); } } } StorageServerHandler(StorageManager storageManager);   }