/** * Send the join operations using the {@link ServiceRequestSender}. A sender can be * a ServiceHost, ServiceClient or a Service. * Caller can also provide batch size to control the rate at which operations are sent. */ public void sendWith(ServiceRequestSender sender, int batchSize) { if (batchSize <= 0) { throw new IllegalArgumentException(ERROR_MSG_INVALID_BATCH_SIZE); } this.batchSize = batchSize; this.sendWith(sender); }
private void send(ServiceRequestSender sender) { validateSendRequest(sender); this.sender = sender; setProxyCompletion(); this.join.sendWith(sender); }
private void clearTransactions(Operation patch, String transactionId, Collection<Operation> clearTransactionRequests) { OperationJoin.create(clearTransactionRequests).setCompletion((ops, exs) -> { if (exs != null) { patch.fail(new IllegalStateException(String.format( "Transaction %s failed to clear from some services", transactionId))); return; } patch.complete(); }).sendWith(this); }
private void deleteServicesAndClearTransactions(Operation patch, String transactionId, Collection<Operation> deleteRequests, Collection<Operation> clearTransactionRequests) { OperationJoin.create(deleteRequests).setCompletion((ops, exs) -> { if (exs != null) { patch.fail(new IllegalStateException(String.format( "Transaction %s failed to delete some services", transactionId))); return; } if (clearTransactionRequests != null && !clearTransactionRequests.isEmpty()) { clearTransactions(patch, transactionId, clearTransactionRequests); } else { patch.complete(); } }).sendWith(this); }
/** * Handle the case when a client requests to abort. */ private void handleAbort(TransactionServiceState existing) { Collection<Operation> ops = createNotifyServicesToAbort(existing); if (ops.isEmpty()) { selfPatch(ResolutionKind.ABORTED); return; } OperationJoin.create(ops) .setCompletion((operations, failures) -> { if (failures != null) { logWarning("Transaction failed to notify some services to abort: %s", failures.toString()); } selfPatch(ResolutionKind.ABORTED); }).sendWith(this); }
@Test public void testJoinWithBatchOnService() throws Throwable { testJoinWithBatch((params) -> OperationJoin.create(params.ops).sendWith( this.services.get(0), params.batchSize)); }
@Test public void testJoinWithBatchOnService() throws Throwable { testJoinWithBatch((params) -> OperationJoin.create(params.ops).sendWith( this.services.get(0), params.batchSize)); }
@Override public void handleDelete(Operation delete) { if (this.pageLinks.isEmpty()) { super.handleDelete(delete); return; } // delete associated pages OperationJoin.create( this.pageLinks.stream().map(link -> Operation.createDelete(this, link).setReferer(getUri()) ) ).setCompletion((ops, exs) -> { if (exs != null) { logWarning("Failed to delete query result pages for broadcast query result %s: %s", getUri(), Utils.toString(exs)); } // delete itself and complete super.handleDelete(delete); }).sendWith(this); }
@Test public void testJoinWithBatchOnHost() throws Throwable { testJoinWithBatch((params) -> OperationJoin.create(params.ops).sendWith(this.host, params.batchSize)); }
@Test public void testJoinWithBatchOnHost() throws Throwable { testJoinWithBatch((params) -> OperationJoin.create(params.ops).sendWith(this.host, params.batchSize)); }
@Test public void testJoinWithBatchOnServiceClient() throws Throwable { testJoinWithBatch((params) -> OperationJoin.create(params.ops).sendWith( this.host.getClient(), params.batchSize)); }
@Test public void testSetOperationsWithStream() throws Throwable { OperationJoin operationJoin = OperationJoin.create(); Operation op1 = createServiceOperation(this.services.get(0)); Operation op2 = createServiceOperation(this.services.get(1)); Operation op3 = createServiceOperation(this.services.get(2)); host.testStart(1); operationJoin .setOperations(Stream.of(op1, op2, op3)) .setCompletion((ops, exs) -> { if (exs != null) { host.failIteration(exs.values().iterator().next()); } else { host.completeIteration(); } }).sendWith(host); host.testWait(); }
@Test public void testJoinWithBatchOnServiceClient() throws Throwable { testJoinWithBatch((params) -> OperationJoin.create(params.ops).sendWith( this.host.getClient(), params.batchSize)); }
@Test public void testSetOperationsWithCollection() throws Throwable { OperationJoin operationJoin = OperationJoin.create(); Operation op1 = createServiceOperation(this.services.get(0)); Operation op2 = createServiceOperation(this.services.get(1)); Operation op3 = createServiceOperation(this.services.get(2)); host.testStart(1); operationJoin .setOperations(Arrays.asList(op1, op2, op3)) .setCompletion((ops, exs) -> { if (exs != null) { host.failIteration(exs.values().iterator().next()); } else { host.completeIteration(); } }).sendWith(host); host.testWait(); }
@Test public void testSetOperationsWithCollection() throws Throwable { OperationJoin operationJoin = OperationJoin.create(); Operation op1 = createServiceOperation(this.services.get(0)); Operation op2 = createServiceOperation(this.services.get(1)); Operation op3 = createServiceOperation(this.services.get(2)); host.testStart(1); operationJoin .setOperations(Arrays.asList(op1, op2, op3)) .setCompletion((ops, exs) -> { if (exs != null) { host.failIteration(exs.values().iterator().next()); } else { host.completeIteration(); } }).sendWith(host); host.testWait(); }
@Test public void testSetOperationsWithStream() throws Throwable { OperationJoin operationJoin = OperationJoin.create(); Operation op1 = createServiceOperation(this.services.get(0)); Operation op2 = createServiceOperation(this.services.get(1)); Operation op3 = createServiceOperation(this.services.get(2)); host.testStart(1); operationJoin .setOperations(Stream.of(op1, op2, op3)) .setCompletion((ops, exs) -> { if (exs != null) { host.failIteration(exs.values().iterator().next()); } else { host.completeIteration(); } }).sendWith(host); host.testWait(); }
@Test public void testSetOperationsFailureWithoutOperations() throws Throwable { OperationJoin operationJoin = OperationJoin.create(); host.testStart(1); try { operationJoin.sendWith(host); host.failIteration(new IllegalStateException("Expected exception")); } catch (IllegalStateException e) { host.completeIteration(); } host.testWait(); }
@Test public void testSetOperationsFailureWithoutOperations() throws Throwable { OperationJoin operationJoin = OperationJoin.create(); host.testStart(1); try { operationJoin.sendWith(host); host.failIteration(new IllegalStateException("Expected exception")); } catch (IllegalStateException e) { host.completeIteration(); } host.testWait(); }
@Test public void testSetOperations() throws Throwable { OperationJoin operationJoin = OperationJoin.create(); Operation op1 = createServiceOperation(this.services.get(0)); Operation op2 = createServiceOperation(this.services.get(1)); Operation op3 = createServiceOperation(this.services.get(2)); host.testStart(1); operationJoin .setOperations(op1, op2, op3) .setCompletion((ops, exs) -> { if (exs != null) { host.failIteration(exs.values().iterator().next()); } else { host.completeIteration(); } }).sendWith(host); host.testWait(); }
@Test public void testSetOperations() throws Throwable { OperationJoin operationJoin = OperationJoin.create(); Operation op1 = createServiceOperation(this.services.get(0)); Operation op2 = createServiceOperation(this.services.get(1)); Operation op3 = createServiceOperation(this.services.get(2)); host.testStart(1); operationJoin .setOperations(op1, op2, op3) .setCompletion((ops, exs) -> { if (exs != null) { host.failIteration(exs.values().iterator().next()); } else { host.completeIteration(); } }).sendWith(host); host.testWait(); }