Example #1
0
  @Test
  public void checkBehavior_of_StorageOperationProcessingDuringRecovery() throws Exception {
    verifyZeroInteractions(storage);
    startNodeAndVerify();

    manageNode(new ControlMessage.Builder().setState(StorageNode.StorageState.RECOVERING.name()));

    for (StorageOperation op : allOperations) {
      node.onStorageRequest(op);
    }

    // all the operations must be queued for further processing after recovery will be completed
    verify(storage, after(2000).never()).process(any());
    verifyZeroInteractions(storage);

    // should process all previously queued operations
    manageNode(new ControlMessage.Builder().setState(StorageNode.StorageState.RUNNING.name()));

    // all the enqueued operation should be processed
    verify(storage, after(1000).times(allOperations.length)).process(any());

    // each successfully processed operation should be acknowledged
    verify(operationContext, times(allOperations.length)).ackOperation(any());

    stopNodeAndVerify();
  }
Example #2
0
  @Test
  public void rejectAllStorageOperationsBeingInInappropriateState() throws Exception {

    // -- generate list of "inappropriate" states
    final List<String> states = new LinkedList<>();
    final EnumSet<StorageNode.StorageState> allowedStates =
        EnumSet.of(StorageNode.StorageState.RECOVERING, StorageNode.StorageState.RUNNING);

    for (StorageNode.StorageState s : StorageNode.StorageState.values()) {
      if (!allowedStates.contains(s)) {
        states.add(s.name());
      }
    }

    // --
    for (String s : states) {
      if (!node.getState().equals(s)) {
        manageNode(new ControlMessage.Builder().setState(s));
      }

      assertEquals(s, node.getState());

      for (StorageOperation op : allOperations) {
        // TODO: rewrite with Exception Matcher to introduce message checking
        try {
          node.onStorageRequest(op);
          fail();
        } catch (IllegalStateException ex) {
        }
      }
    }
  }