use of org.hyperledger.fabric.sdk.transaction.TransactionContext in project fabric-sdk-java by hyperledger.
the class ChannelTest method testProposalBuilderWithMetaInf.
@Test
public void testProposalBuilderWithMetaInf() throws Exception {
InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
installProposalBuilder.chaincodePath("github.com/example_cc");
installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
installProposalBuilder.chaincodeName("example_cc.go");
installProposalBuilder.setChaincodeMetaInfLocation(new File("src/test/fixture/meta-infs/test1"));
installProposalBuilder.chaincodeVersion("1");
Channel channel = hfclient.newChannel("testProposalBuilderWithMetaInf");
TestUtils.MockUser mockUser = getMockUser("rick", "rickORG");
TransactionContext transactionContext = new TransactionContext(channel, mockUser, CryptoSuite.Factory.getCryptoSuite());
installProposalBuilder.context(transactionContext);
// Build it get the proposal. Then unpack it to see if it's what we expect.
FabricProposal.Proposal proposal = installProposalBuilder.build();
FabricProposal.ChaincodeProposalPayload chaincodeProposalPayload = FabricProposal.ChaincodeProposalPayload.parseFrom(proposal.getPayload());
Chaincode.ChaincodeInvocationSpec chaincodeInvocationSpec = Chaincode.ChaincodeInvocationSpec.parseFrom(chaincodeProposalPayload.getInput());
Chaincode.ChaincodeSpec chaincodeSpec = chaincodeInvocationSpec.getChaincodeSpec();
Chaincode.ChaincodeInput input = chaincodeSpec.getInput();
Chaincode.ChaincodeDeploymentSpec chaincodeDeploymentSpec = Chaincode.ChaincodeDeploymentSpec.parseFrom(input.getArgs(1));
ByteString codePackage = chaincodeDeploymentSpec.getCodePackage();
ArrayList tarBytesToEntryArrayList = tarBytesToEntryArrayList(codePackage.toByteArray());
ArrayList<String> expect = new ArrayList(Arrays.asList(new String[] { "META-INF/statedb/couchdb/indexes/MockFakeIndex.json", "src/github.com/example_cc/example_cc.go" }));
assertArrayListEquals("Tar in Install Proposal's codePackage does not have expected entries. ", expect, tarBytesToEntryArrayList);
}
use of org.hyperledger.fabric.sdk.transaction.TransactionContext in project fabric-sdk-java by hyperledger.
the class ChannelTest method testProposalBuilderWithMetaInfEmpty.
@Test
public void testProposalBuilderWithMetaInfEmpty() throws Exception {
thrown.expect(java.lang.IllegalArgumentException.class);
thrown.expectMessage(matchesRegex("The META-INF directory.*src.test.fixture.meta-infs.emptyMetaInf.META-INF is empty\\."));
// make it cause git won't check in empty directory
File emptyINF = new File("src/test/fixture/meta-infs/emptyMetaInf/META-INF");
if (!emptyINF.exists()) {
emptyINF.mkdirs();
emptyINF.deleteOnExit();
}
InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
installProposalBuilder.chaincodePath("github.com/example_cc");
installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
installProposalBuilder.chaincodeName("example_cc.go");
installProposalBuilder.chaincodeVersion("1");
// points into which is not what's expected.
installProposalBuilder.setChaincodeMetaInfLocation(new File("src/test/fixture/meta-infs/emptyMetaInf"));
Channel channel = hfclient.newChannel("testProposalBuilderWithMetaInfEmpty");
TransactionContext transactionContext = new TransactionContext(channel, getMockUser("rick", "rickORG"), CryptoSuite.Factory.getCryptoSuite());
installProposalBuilder.context(transactionContext);
// Build it get the proposal. Then unpack it to see if it's what we epect.
FabricProposal.Proposal proposal = installProposalBuilder.build();
}
use of org.hyperledger.fabric.sdk.transaction.TransactionContext in project fabric-sdk-java by hyperledger.
the class ChannelTest method testProposalBuilderWithMetaInfExistsNOT.
@Test
public void testProposalBuilderWithMetaInfExistsNOT() throws Exception {
thrown.expect(java.lang.IllegalArgumentException.class);
thrown.expectMessage(matchesRegex("Directory to find chaincode META-INF.*tmp.fdsjfksfj.fjksfjskd.fjskfjdsk.should never exist does not exist"));
InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
installProposalBuilder.chaincodePath("github.com/example_cc");
installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
installProposalBuilder.chaincodeName("example_cc.go");
installProposalBuilder.chaincodeVersion("1");
// points into which is not what's expected.
installProposalBuilder.setChaincodeMetaInfLocation(new File("/tmp/fdsjfksfj/fjksfjskd/fjskfjdsk/should never exist"));
Channel channel = hfclient.newChannel("testProposalBuilderWithMetaInfExistsNOT");
TransactionContext transactionContext = new TransactionContext(channel, getMockUser("rick", "rickORG"), CryptoSuite.Factory.getCryptoSuite());
installProposalBuilder.context(transactionContext);
// Build it get the proposal. Then unpack it to see if it's what we epect.
installProposalBuilder.build();
}
use of org.hyperledger.fabric.sdk.transaction.TransactionContext in project fabric-sdk-java by hyperledger.
the class ChannelTest method testProposalBuilderWithNoMetaInfDir.
@Test
public void testProposalBuilderWithNoMetaInfDir() throws Exception {
thrown.expect(java.lang.IllegalArgumentException.class);
thrown.expectMessage(matchesRegex("The META-INF directory does not exist in.*src.test.fixture.meta-infs.test1.META-INF"));
InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
installProposalBuilder.chaincodePath("github.com/example_cc");
installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
installProposalBuilder.chaincodeName("example_cc.go");
installProposalBuilder.chaincodeVersion("1");
// points into which is not what's expected.
installProposalBuilder.setChaincodeMetaInfLocation(new File("src/test/fixture/meta-infs/test1/META-INF"));
Channel channel = hfclient.newChannel("testProposalBuilderWithNoMetaInfDir");
TransactionContext transactionContext = new TransactionContext(channel, getMockUser("rick", "rickORG"), CryptoSuite.Factory.getCryptoSuite());
installProposalBuilder.context(transactionContext);
// Build it get the proposal. Then unpack it to see if it's what we epect.
installProposalBuilder.build();
}
use of org.hyperledger.fabric.sdk.transaction.TransactionContext in project fabric-sdk-java by hyperledger.
the class Channel method seekBlock.
private int seekBlock(SeekInfo seekInfo, List<DeliverResponse> deliverResponses, Orderer ordererIn) throws TransactionException {
logger.trace(format("seekBlock for channel %s", name));
final long start = System.currentTimeMillis();
@SuppressWarnings("UnusedAssignment") int statusRC = 404;
try {
do {
statusRC = 404;
final Orderer orderer = ordererIn != null ? ordererIn : getRandomOrderer();
TransactionContext txContext = getTransactionContext();
DeliverResponse[] deliver = orderer.sendDeliver(createSeekInfoEnvelope(txContext, seekInfo, orderer.getClientTLSCertificateDigest()));
if (deliver.length < 1) {
logger.warn(format("Genesis block for channel %s fetch bad deliver missing status block only got blocks:%d", name, deliver.length));
// odd so lets try again....
statusRC = 404;
} else {
DeliverResponse status = deliver[0];
statusRC = status.getStatusValue();
if (statusRC == 404 || statusRC == 503) {
// 404 - block not found. 503 - service not available usually means kafka is not ready but starting.
logger.warn(format("Bad deliver expected status 200 got %d, Channel %s", status.getStatusValue(), name));
// keep trying... else
statusRC = 404;
} else if (statusRC != 200) {
// Assume for anything other than 200 we have a non retryable situation
throw new TransactionException(format("Bad newest block expected status 200 got %d, Channel %s", status.getStatusValue(), name));
} else {
if (deliver.length < 2) {
throw new TransactionException(format("Newest block for channel %s fetch bad deliver missing genesis block only got %d:", name, deliver.length));
} else {
deliverResponses.addAll(Arrays.asList(deliver));
}
}
}
if (200 != statusRC) {
long duration = System.currentTimeMillis() - start;
if (duration > config.getGenesisBlockWaitTime()) {
throw new TransactionException(format("Getting block time exceeded %s seconds for channel %s", Long.toString(TimeUnit.MILLISECONDS.toSeconds(duration)), name));
}
try {
// try again
Thread.sleep(ORDERER_RETRY_WAIT_TIME);
} catch (InterruptedException e) {
TransactionException te = new TransactionException("seekBlock thread Sleep", e);
logger.warn(te.getMessage(), te);
}
}
} while (statusRC != 200);
} catch (TransactionException e) {
logger.error(e.getMessage(), e);
throw e;
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new TransactionException(e);
}
return statusRC;
}
Aggregations