public void whenNormalOperation(boolean partitionSpecific, boolean remoteCall) {
    BasicBackPressureService service = newEnabledBackPressureService();

    Operation op;
    if (partitionSpecific) {
      PartitionSpecificOperation partitionOp = new PartitionSpecificOperation();
      partitionOp.setPartitionId(0);
      op = partitionOp;
    } else {
      op = new GenericOperation();
      op.setPartitionId(-1);
    }

    Connection connection = null;
    if (remoteCall) {
      connection = mock(Connection.class);
      OperationAccessor.setConnection(op, connection);
    }

    int expected = SYNC_WINDOW - 1;
    for (int k = 0; k < SYNC_WINDOW; k++) {
      boolean result = service.isBackPressureNeeded(op);
      assertFalse("no back pressure expected", result);

      AtomicInteger syncDelay = service.getSyncDelay(connection, op.getPartitionId());
      assertEquals(expected, syncDelay.get());
      expected--;
    }

    boolean result = service.isBackPressureNeeded(op);
    assertTrue("back pressure expected", result);

    AtomicInteger syncDelay = service.getSyncDelay(connection, op.getPartitionId());
    assertValidSyncDelay(syncDelay);
  }
Ejemplo n.º 2
0
 private void ensureBackupOperationInitialized() {
   if (backupOp.getNodeEngine() == null) {
     backupOp.setNodeEngine(getNodeEngine());
     backupOp.setPartitionId(getPartitionId());
     backupOp.setReplicaIndex(getReplicaIndex());
     backupOp.setCallerUuid(getCallerUuid());
     OperationAccessor.setCallerAddress(backupOp, getCallerAddress());
     OperationAccessor.setInvocationTime(backupOp, Clock.currentTimeMillis());
     backupOp.setOperationResponseHandler(createEmptyResponseHandler());
   }
 }
  @Test
  public void whenGeneric() {
    initExecutor();

    final AtomicReference<Thread> executingThread = new AtomicReference<Thread>();

    Operation op =
        new Operation() {
          @Override
          public void run() throws Exception {
            executingThread.set(Thread.currentThread());
          }
        };
    executor.execute(op.setPartitionId(-1));

    assertTrueEventually(
        new AssertTask() {
          @Override
          public void run() throws Exception {
            assertInstanceOf(GenericOperationThread.class, executingThread.get());
          }
        });
  }