Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 2adcdbc

Browse files
committed
FAB-8074 Misc fixes see description
Change-Id: I7bfcb0a312a6000def95376cfc3cb8c821086265 Signed-off-by: rickr <cr22rc@gmail.com>
1 parent e478cb9 commit 2adcdbc

File tree

7 files changed

+71
-22
lines changed

7 files changed

+71
-22
lines changed

src/main/java/org/hyperledger/fabric/sdk/Channel.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,15 @@ private Collection<ProposalResponse> sendProposal(TransactionRequest proposalReq
23002300
checkPeers(peers);
23012301

23022302
if (null == proposalRequest) {
2303-
throw new InvalidArgumentException("sendProposal queryProposalRequest is null");
2303+
throw new InvalidArgumentException("The proposalRequest is null");
2304+
}
2305+
2306+
if (Utils.isNullOrEmpty(proposalRequest.getFcn())) {
2307+
throw new InvalidArgumentException("The proposalRequest's fcn is null or empty.");
2308+
}
2309+
2310+
if (proposalRequest.getChaincodeID() == null) {
2311+
throw new InvalidArgumentException("The proposalRequest's chaincode ID is null");
23042312
}
23052313

23062314
proposalRequest.setSubmitted();

src/main/java/org/hyperledger/fabric/sdk/HFClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public Channel deSerializeChannel(byte[] channelBytes)
278278
/**
279279
* newPeer create a new peer
280280
*
281-
* @param name
281+
* @param name name of peer.
282282
* @param grpcURL to the peer's location
283283
* @param properties <p>
284284
* Supported properties
@@ -302,6 +302,9 @@ public Channel deSerializeChannel(byte[] channelBytes)
302302
* hostname verifications during TLS handshake.
303303
* </li>
304304
* <li>
305+
* peerEventRegistrationWaitTime - Time in milliseconds to wait for peer eventing service registration.
306+
* </li>
307+
* <li>
305308
* grpc.NettyChannelBuilderOption.&lt;methodName&gt; where methodName is any method on
306309
* grpc ManagedChannelBuilder. If more than one argument to the method is needed then the
307310
* parameters need to be supplied in an array of Objects.

src/main/java/org/hyperledger/fabric/sdk/OrdererClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ Ab.BroadcastResponse sendTransaction(Common.Envelope envelope) throws Exception
141141
public void onNext(Ab.BroadcastResponse resp) {
142142
// logger.info("Got Broadcast response: " + resp);
143143
logger.debug("resp status value: " + resp.getStatusValue() + ", resp: " + resp.getStatus());
144-
ret[0] = resp;
144+
if (resp.getStatus() == Common.Status.SUCCESS) {
145+
ret[0] = resp;
146+
} else {
147+
throwable[0] = new TransactionException(format("Channel %s orderer %s status returned failure code %d (%s) during order registration",
148+
channelName, name, resp.getStatusValue(), resp.getStatus().name()));
149+
}
145150
finishLatch.countDown();
146151

147152
}

src/main/java/org/hyperledger/fabric/sdk/PeerEventServiceClient.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.grpc.stub.StreamObserver;
2929
import org.apache.commons.logging.Log;
3030
import org.apache.commons.logging.LogFactory;
31+
import org.hyperledger.fabric.protos.common.Common;
3132
import org.hyperledger.fabric.protos.common.Common.Envelope;
3233
import org.hyperledger.fabric.protos.orderer.Ab;
3334
import org.hyperledger.fabric.protos.orderer.Ab.SeekInfo;
@@ -45,19 +46,18 @@
4546
import static org.hyperledger.fabric.protos.peer.PeerEvents.DeliverResponse.TypeCase.STATUS;
4647
import static org.hyperledger.fabric.sdk.transaction.ProtoUtils.createSeekInfoEnvelope;
4748

48-
4949
/**
5050
* Sample client code that makes gRPC calls to the server.
5151
*/
5252
class PeerEventServiceClient {
5353
private static final Config config = Config.getConfig();
54-
private static final long ORDERER_WAIT_TIME = config.getOrdererWaitTime();
54+
private static final long PEER_EVENT_REGISTRATION_WAIT_TIME = config.getPeerEventRegistrationWaitTime();
5555
private static final Log logger = LogFactory.getLog(PeerEventServiceClient.class);
5656
private final String channelName;
5757
private final ManagedChannelBuilder channelBuilder;
5858
private final String name;
5959
private final String url;
60-
private final long ordererWaitTimeMilliSecs;
60+
private final long peerEventRegistrationWaitTimeMilliSecs;
6161
private final PeerOptions peerOptions;
6262
private final boolean filterBlock;
6363
Properties properties = new Properties();
@@ -70,7 +70,7 @@ class PeerEventServiceClient {
7070
private transient Peer peer;
7171

7272
/**
73-
* Construct client for accessing Orderer server using the existing managedChannel.
73+
* Construct client for accessing Peer eventing service using the existing managedChannel.
7474
*/
7575
PeerEventServiceClient(Peer peer, ManagedChannelBuilder<?> channelBuilder, Properties properties, PeerOptions peerOptions) {
7676

@@ -86,22 +86,22 @@ class PeerEventServiceClient {
8686

8787
if (null == properties) {
8888

89-
ordererWaitTimeMilliSecs = ORDERER_WAIT_TIME;
89+
peerEventRegistrationWaitTimeMilliSecs = PEER_EVENT_REGISTRATION_WAIT_TIME;
9090

9191
} else {
9292
this.properties = properties;
9393

94-
String ordererWaitTimeMilliSecsString = properties.getProperty("ordererWaitTimeMilliSecs", Long.toString(ORDERER_WAIT_TIME));
94+
String peerEventRegistrationWaitTime = properties.getProperty("peerEventRegistrationWaitTime", Long.toString(PEER_EVENT_REGISTRATION_WAIT_TIME));
9595

96-
long tempOrdererWaitTimeMilliSecs = ORDERER_WAIT_TIME;
96+
long tempPeerWaitTimeMilliSecs = PEER_EVENT_REGISTRATION_WAIT_TIME;
9797

9898
try {
99-
tempOrdererWaitTimeMilliSecs = Long.parseLong(ordererWaitTimeMilliSecsString);
99+
tempPeerWaitTimeMilliSecs = Long.parseLong(peerEventRegistrationWaitTime);
100100
} catch (NumberFormatException e) {
101-
logger.warn(format("Orderer %s wait time %s not parsable.", name, ordererWaitTimeMilliSecsString), e);
101+
logger.warn(format("Peer event service registration %s wait time %s not parsable.", name, peerEventRegistrationWaitTime), e);
102102
}
103103

104-
ordererWaitTimeMilliSecs = tempOrdererWaitTimeMilliSecs;
104+
peerEventRegistrationWaitTimeMilliSecs = tempPeerWaitTimeMilliSecs;
105105
}
106106

107107
}
@@ -202,21 +202,30 @@ public void onNext(DeliverResponse resp) {
202202
done = true;
203203
logger.debug(format("DeliverResponse channel %s peer %s setting done.",
204204
channelName, peer.getName()));
205-
retList.add(0, resp);
206205

207-
finishLatch.countDown();
206+
if (resp.getStatus() == Common.Status.SUCCESS) {
207+
retList.add(0, resp);
208+
} else {
209+
210+
throwableList.add(new TransactionException(format("Channel %s peer %s Status returned failure code %d (%s) during peer service event registration",
211+
channelName, peer.getName(), resp.getStatusValue(), resp.getStatus().name())));
212+
}
208213

209214
} else if (typeCase == FILTERED_BLOCK || typeCase == BLOCK) {
210215
logger.trace(format("Channel %s peer %s got event block hex hashcode: %016x, block number: %d",
211216
channelName, peer.getName(), resp.getBlock().hashCode(), resp.getBlock().getHeader().getNumber()));
212217
retList.add(resp);
213-
finishLatch.countDown();
218+
214219
channelEventQue.addBEvent(new BlockEvent(peer, resp));
215220
} else {
216221
logger.error(format("Channel %s peer %s got event block with unknown type: %s, %d",
217-
channelName, peer.getName(), typeCase.name(), typeCase.getNumber())
218-
);
222+
channelName, peer.getName(), typeCase.name(), typeCase.getNumber()));
223+
224+
throwableList.add(new TransactionException(format("Channel %s peer %s Status got unknown type %s, %d",
225+
channelName, peer.getName(), typeCase.name(), typeCase.getNumber())));
226+
219227
}
228+
finishLatch.countDown();
220229

221230
}
222231

@@ -229,7 +238,6 @@ public void onError(Throwable t) {
229238
if (!shutdown) {
230239
logger.error(format("Received error on channel %s, peer %s, url %s, %s",
231240
channelName, name, url, t.getMessage()), t);
232-
233241
done = true;
234242
throwableList.add(t);
235243
finishLatch.countDown();
@@ -259,10 +267,9 @@ public void onCompleted() {
259267
//nso.onCompleted();
260268

261269
try {
262-
// if (!finishLatch.await(ordererWaitTimeMilliSecs, TimeUnit.MILLISECONDS)) {
263-
if (!finishLatch.await(9999999, TimeUnit.MILLISECONDS)) {
270+
if (!finishLatch.await(peerEventRegistrationWaitTimeMilliSecs, TimeUnit.MILLISECONDS)) {
264271
TransactionException ex = new TransactionException(format(
265-
"Channel %s connect time exceeded for peer eventing service %s, timed out at %d ms.", channelName, name, ordererWaitTimeMilliSecs));
272+
"Channel %s connect time exceeded for peer eventing service %s, timed out at %d ms.", channelName, name, peerEventRegistrationWaitTimeMilliSecs));
266273
logger.error(ex.getMessage(), ex);
267274
throw ex;
268275
}

src/main/java/org/hyperledger/fabric/sdk/helper/Config.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class Config {
5151
public static final String TRANSACTION_CLEANUP_UP_TIMEOUT_WAIT_TIME = "org.hyperledger.fabric.sdk.client.transaction_cleanup_up_timeout_wait_time";
5252
public static final String ORDERER_RETRY_WAIT_TIME = "org.hyperledger.fabric.sdk.orderer_retry.wait_time";
5353
public static final String ORDERER_WAIT_TIME = "org.hyperledger.fabric.sdk.orderer.ordererWaitTimeMilliSecs";
54+
public static final String PEER_EVENT_REGISTRATION_WAIT_TIME = "org.hyperledger.fabric.sdk.peer.eventRegistration.wait_time";
5455
public static final String EVENTHUB_CONNECTION_WAIT_TIME = "org.hyperledger.fabric.sdk.eventhub_connection.wait_time";
5556
public static final String GENESISBLOCK_WAIT_TIME = "org.hyperledger.fabric.sdk.channel.genesisblock_wait_time";
5657
/**
@@ -105,6 +106,7 @@ private Config() {
105106
defaultProperty(CHANNEL_CONFIG_WAIT_TIME, "15000");
106107
defaultProperty(ORDERER_RETRY_WAIT_TIME, "200");
107108
defaultProperty(ORDERER_WAIT_TIME, "10000");
109+
defaultProperty(PEER_EVENT_REGISTRATION_WAIT_TIME, "2000");
108110
defaultProperty(EVENTHUB_CONNECTION_WAIT_TIME, "1000");
109111
defaultProperty(GENESISBLOCK_WAIT_TIME, "5000");
110112
/**
@@ -348,6 +350,15 @@ public long getOrdererWaitTime() {
348350
return Long.parseLong(getProperty(ORDERER_WAIT_TIME));
349351
}
350352

353+
/**
354+
* getPeerEventRegistrationWaitTime
355+
*
356+
* @return time in milliseconds to wait for peer eventing service to wait for event registration
357+
*/
358+
public long getPeerEventRegistrationWaitTime() {
359+
return Long.parseLong(getProperty(PEER_EVENT_REGISTRATION_WAIT_TIME));
360+
}
361+
351362
public long getEventHubConnectionWaitTime() {
352363
return Long.parseLong(getProperty(EVENTHUB_CONNECTION_WAIT_TIME));
353364
}

src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,17 @@ public void setup() {
225225
SampleOrg sampleOrg = testConfig.getIntegrationTestsSampleOrg("peerOrg1");
226226
Channel fooChannel = reconstructChannel(FOO_CHANNEL_NAME, client, sampleOrg);
227227
runChannel(client, fooChannel, sampleOrg, 0);
228+
assertFalse(fooChannel.isShutdown());
229+
assertTrue(fooChannel.isInitialized());
228230
fooChannel.shutdown(true); //clean up resources no longer needed.
231+
assertTrue(fooChannel.isShutdown());
229232
out("\n");
233+
230234
sampleOrg = testConfig.getIntegrationTestsSampleOrg("peerOrg2");
231235
Channel barChannel = reconstructChannel(BAR_CHANNEL_NAME, client, sampleOrg);
232236
runChannel(client, barChannel, sampleOrg, 100); //run a newly constructed foo channel with different b value!
237+
assertFalse(barChannel.isShutdown());
238+
assertTrue(barChannel.isInitialized());
233239

234240
if (!testConfig.isRunningAgainstFabric10()) { //Peer eventing service support started with v1.1
235241

@@ -696,6 +702,9 @@ private Channel reconstructChannel(String name, HFClient client, SampleOrg sampl
696702

697703
}
698704

705+
assertTrue(newChannel.isInitialized());
706+
assertFalse(newChannel.isShutdown());
707+
699708
out("Finished reconstructing channel %s.", name);
700709

701710
return newChannel;

src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,28 @@ sampleOrgDomainName, format("/users/Admin@%s/msp/keystore", sampleOrgDomainName)
244244
Channel fooChannel = constructChannel(FOO_CHANNEL_NAME, client, sampleOrg);
245245
runChannel(client, fooChannel, true, sampleOrg, 0);
246246

247+
assertFalse(fooChannel.isShutdown());
247248
fooChannel.shutdown(true); // Force foo channel to shutdown clean up resources.
249+
assertTrue(fooChannel.isShutdown());
248250

249251
assertNull(client.getChannel(FOO_CHANNEL_NAME));
250252
out("\n");
251253

252254
sampleOrg = testConfig.getIntegrationTestsSampleOrg("peerOrg2");
253255
Channel barChannel = constructChannel(BAR_CHANNEL_NAME, client, sampleOrg);
256+
assertTrue(barChannel.isInitialized());
254257
/**
255258
* sampleStore.saveChannel uses {@link Channel#serializeChannel()}
256259
*/
257260
sampleStore.saveChannel(barChannel);
261+
assertFalse(barChannel.isShutdown());
258262
runChannel(client, barChannel, true, sampleOrg, 100); //run a newly constructed bar channel with different b value!
259263
//let bar channel just shutdown so we have both scenarios.
260264

261265
out("\nTraverse the blocks for chain %s ", barChannel.getName());
262266
blockWalker(client, barChannel);
267+
assertFalse(barChannel.isShutdown());
268+
assertTrue(barChannel.isInitialized());
263269
out("That's all folks!");
264270

265271
} catch (Exception e) {

0 commit comments

Comments
 (0)