org.hyperledger.fabric.sdk.exception.TransactionEventException Java Examples
The following examples show how to use
org.hyperledger.fabric.sdk.exception.TransactionEventException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NetworkConfigIT.java From fabric-sdk-java with Apache License 2.0 | 4 votes |
@Test public void testUpdate1() throws Exception { // Setup client and channel instances HFClient client = getTheClient(); Channel channel = constructChannel(client, FOO_CHANNEL_NAME); final ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(CHAIN_CODE_NAME) .setVersion(CHAIN_CODE_VERSION) .setPath(CHAIN_CODE_PATH).build(); final String channelName = channel.getName(); out("Running testUpdate1 - Channel %s", channelName); final Collection<String> peersOrganizationMSPIDs = channel.getPeersOrganizationMSPIDs(); assertNotNull(peersOrganizationMSPIDs); assertEquals(1, peersOrganizationMSPIDs.size()); assertEquals("Org1MSP", peersOrganizationMSPIDs.iterator().next()); int moveAmount = 5; String originalVal = queryChaincodeForCurrentValue(client, channel, chaincodeID); String newVal = "" + (Integer.parseInt(originalVal) + moveAmount); out("Original value = %s", originalVal); //user registered user client.setUserContext(orgRegisteredUsers.get("Org1")); // only using org1 // Move some assets moveAmount(client, channel, chaincodeID, "a", "b", "" + moveAmount, null).thenApply(transactionEvent -> { // Check that they were moved queryChaincodeForExpectedValue(client, channel, newVal, chaincodeID); return null; }).thenApply(transactionEvent -> { // Move them back try { return moveAmount(client, channel, chaincodeID, "b", "a", "" + moveAmount, null).get(testConfig.getTransactionWaitTime(), TimeUnit.SECONDS); } catch (Exception e) { throw new RuntimeException(e); } }).thenApply(transactionEvent -> { // Check that they were moved back queryChaincodeForExpectedValue(client, channel, originalVal, chaincodeID); return null; }).exceptionally(e -> { if (e instanceof CompletionException && e.getCause() != null) { e = e.getCause(); } if (e instanceof TransactionEventException) { BlockEvent.TransactionEvent te = ((TransactionEventException) e).getTransactionEvent(); if (te != null) { e.printStackTrace(System.err); fail(format("Transaction with txid %s failed. %s", te.getTransactionID(), e.getMessage())); } } e.printStackTrace(System.err); fail(format("Test failed with %s exception %s", e.getClass().getName(), e.getMessage())); return null; }).get(testConfig.getTransactionWaitTime(), TimeUnit.SECONDS); channel.shutdown(true); // Force channel to shutdown clean up resources. out("testUpdate1 - done"); out("That's all folks!"); }