use of java.util.concurrent.CompletionException in project photon-model by vmware.
the class TestAWSClientManagement method testAWSClientManagementArn.
@Test
public void testAWSClientManagementArn() throws Throwable {
this.ec2ClientReferenceCount = getClientReferenceCount(AwsClientType.EC2);
this.host.setTimeoutSeconds(60);
// Getting a reference to client managers in the test
AWSClientManager ec2ClientManager = getClientManager(AwsClientType.EC2);
ec2ClientManager.cleanUpArnCache();
assertEquals(this.ec2ClientReferenceCount + 1, getClientReferenceCount(AwsClientType.EC2));
this.creds = new AuthCredentialsServiceState();
this.creds.customProperties = new HashMap<>();
this.creds.customProperties.put(ARN_KEY, this.arn);
this.creds.customProperties.put(EXTERNAL_ID_KEY, this.externalId);
TestContext waitContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
waitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
waitContext.complete();
});
waitContext.await();
Assert.assertNotNull(this.client);
this.clientCacheCount = ec2ClientManager.getCacheCount();
// Requesting another AWS client with the same set of credentials will not
// create a new entry in the cache
AmazonEC2AsyncClient oldClient = this.client;
TestContext nextContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
nextContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
nextContext.complete();
});
nextContext.await();
Assert.assertNotNull(this.client);
Assert.assertEquals(oldClient, this.client);
assertEquals(this.clientCacheCount, ec2ClientManager.getCacheCount());
}
use of java.util.concurrent.CompletionException in project photon-model by vmware.
the class TestAWSClientManagement method testAWSClientManagementArnDr.
@Test
public void testAWSClientManagementArnDr() throws Throwable {
this.ec2ClientReferenceCount = getClientReferenceCount(AwsClientType.EC2);
this.host.setTimeoutSeconds(60);
// Getting a reference to client managers in the test
AWSClientManager ec2ClientManager = getClientManager(AwsClientType.EC2);
ec2ClientManager.cleanUpArnCache();
assertEquals(this.ec2ClientReferenceCount + 1, getClientReferenceCount(AwsClientType.EC2));
this.creds = new AuthCredentialsServiceState();
this.creds.customProperties = new HashMap<>();
this.creds.customProperties.put(ARN_KEY, this.arn);
this.creds.customProperties.put(EXTERNAL_ID_KEY, this.externalId);
TestContext waitContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
waitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
waitContext.complete();
});
waitContext.await();
Assert.assertNotNull(this.client);
this.clientCacheCount = ec2ClientManager.getCacheCount();
// Requesting another AWS client with the same set of credentials will not
// create a new entry in the cache
AmazonEC2AsyncClient oldClient = this.client;
TestContext nextContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
nextContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
nextContext.complete();
});
nextContext.await();
Assert.assertNotNull(this.client);
Assert.assertEquals(oldClient, this.client);
assertEquals(this.clientCacheCount, ec2ClientManager.getCacheCount());
}
use of java.util.concurrent.CompletionException in project photon-model by vmware.
the class TestAWSClientManagement method testAWSClientManagement.
@Test
public void testAWSClientManagement() throws Throwable {
this.ec2ClientReferenceCount = getClientReferenceCount(AwsClientType.EC2);
this.cloudWatchClientReferenceCount = getClientReferenceCount(AwsClientType.CLOUD_WATCH);
this.host.setTimeoutSeconds(60);
// Getting a reference to client managers in the test
AWSClientManager ec2ClientManager = getClientManager(AwsClientType.EC2);
ec2ClientManager.cleanUpArnCache();
@SuppressWarnings("unused") AWSClientManager cloudWatchClientManager = getClientManager(AwsClientType.CLOUD_WATCH);
cloudWatchClientManager.cleanUpArnCache();
assertEquals(this.ec2ClientReferenceCount + 1, getClientReferenceCount(AwsClientType.EC2));
assertEquals(this.cloudWatchClientReferenceCount + 1, getClientReferenceCount(AwsClientType.CLOUD_WATCH));
// Getting an AWSclient from the client manager
this.creds = new AuthCredentialsServiceState();
this.creds.privateKey = this.accessKey;
this.creds.privateKeyId = this.secretKey;
TestContext waitContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
waitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
waitContext.complete();
});
waitContext.await();
this.clientCacheCount = ec2ClientManager.getCacheCount();
// Requesting another AWS client with the same set of credentials will not
// create a new entry in the cache
TestContext nextContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
nextContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
nextContext.complete();
});
nextContext.await();
assertEquals(this.clientCacheCount, ec2ClientManager.getCacheCount());
// Emulating shutdown of individual services to check that the client resources are
// cleaned up as expected.
this.host.sendAndWaitExpectSuccess(Operation.createDelete(UriUtils.buildUri(this.host, AWSInstanceService.SELF_LINK)));
assertEquals(this.ec2ClientReferenceCount, getClientReferenceCount(AwsClientType.EC2));
this.host.sendAndWaitExpectSuccess(Operation.createDelete(UriUtils.buildUri(this.host, AWSStatsService.SELF_LINK)));
assertEquals(this.cloudWatchClientReferenceCount, getClientReferenceCount(AwsClientType.CLOUD_WATCH));
// Returning the references from the test
returnClientManager(ec2ClientManager, AwsClientType.EC2);
assertEquals(this.ec2ClientReferenceCount - 1, getClientReferenceCount(AwsClientType.EC2));
}
use of java.util.concurrent.CompletionException in project fabric-sdk-java by hyperledger.
the class NetworkConfigIT method queryChaincodeForCurrentValue.
// Returns the current value of b's assets
private static String queryChaincodeForCurrentValue(HFClient client, Channel channel, ChaincodeID chaincodeID) {
out("Now query chaincode on channel %s for the current value of b", channel.getName());
QueryByChaincodeRequest queryByChaincodeRequest = client.newQueryProposalRequest();
queryByChaincodeRequest.setArgs("b");
queryByChaincodeRequest.setFcn("query");
queryByChaincodeRequest.setChaincodeID(chaincodeID);
Collection<ProposalResponse> queryProposals;
try {
queryProposals = channel.queryByChaincode(queryByChaincodeRequest);
} catch (Exception e) {
throw new CompletionException(e);
}
String expect = null;
for (ProposalResponse proposalResponse : queryProposals) {
if (!proposalResponse.isVerified() || proposalResponse.getStatus() != Status.SUCCESS) {
fail("Failed query proposal from peer " + proposalResponse.getPeer().getName() + " status: " + proposalResponse.getStatus() + ". Messages: " + proposalResponse.getMessage() + ". Was verified : " + proposalResponse.isVerified());
} else {
String payload = proposalResponse.getProposalResponse().getResponse().getPayload().toStringUtf8();
out("Query payload of b from peer %s returned %s", proposalResponse.getPeer().getName(), payload);
if (expect != null) {
assertEquals(expect, payload);
} else {
expect = payload;
}
}
}
return expect;
}
use of java.util.concurrent.CompletionException in project fabric-sdk-java by hyperledger.
the class End2endAndBackAgainIT method moveAmount.
CompletableFuture<BlockEvent.TransactionEvent> moveAmount(HFClient client, Channel channel, ChaincodeID chaincodeID, String moveAmount, User user) {
try {
Collection<ProposalResponse> successful = new LinkedList<>();
Collection<ProposalResponse> failed = new LinkedList<>();
// /////////////
// / Send transaction proposal to all peers
TransactionProposalRequest transactionProposalRequest = client.newTransactionProposalRequest();
transactionProposalRequest.setChaincodeID(chaincodeID);
transactionProposalRequest.setFcn("move");
transactionProposalRequest.setArgs(new byte[][] { // test using bytes .. end2end uses Strings.
"a".getBytes(UTF_8), "b".getBytes(UTF_8), moveAmount.getBytes(UTF_8) });
transactionProposalRequest.setProposalWaitTime(testConfig.getProposalWaitTime());
if (user != null) {
// specific user use that
transactionProposalRequest.setUserContext(user);
}
out("sending transaction proposal to all peers with arguments: move(a,b,%s)", moveAmount);
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(transactionProposalRequest);
for (ProposalResponse response : invokePropResp) {
if (response.getStatus() == Status.SUCCESS) {
out("Successful transaction proposal response Txid: %s from peer %s", response.getTransactionID(), response.getPeer().getName());
successful.add(response);
} else {
failed.add(response);
}
}
out("Received %d transaction proposal responses. Successful+verified: %d . Failed: %d", invokePropResp.size(), successful.size(), failed.size());
if (failed.size() > 0) {
ProposalResponse firstTransactionProposalResponse = failed.iterator().next();
throw new ProposalException(format("Not enough endorsers for invoke(move a,b,%s):%d endorser error:%s. Was verified:%b", moveAmount, firstTransactionProposalResponse.getStatus().getStatus(), firstTransactionProposalResponse.getMessage(), firstTransactionProposalResponse.isVerified()));
}
out("Successfully received transaction proposal responses.");
// //////////////////////////
// Send transaction to orderer
out("Sending chaincode transaction(move a,b,%s) to orderer.", moveAmount);
if (user != null) {
return channel.sendTransaction(successful, user);
}
return channel.sendTransaction(successful);
} catch (Exception e) {
throw new CompletionException(e);
}
}
Aggregations