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

Commit 1475a3d

Browse files
committed
FAB-11125 Remove reference EventHub
Change-Id: I2365df4b2bc9235cce2172b72a68c6c219e26b96 Signed-off-by: rickr <cr22rc@gmail.com>
1 parent 518114c commit 1475a3d

File tree

4 files changed

+76
-12
lines changed

4 files changed

+76
-12
lines changed

src/test/cirun.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export IMAGE_TAG_FABRIC_CA=:x86_64-1.0.0
4646
# set which Fabric generated configuations is used.
4747
export FAB_CONFIG_GEN_VERS="v1.0"
4848
else
49-
export ORG_HYPERLEDGER_FABRIC_SDKTEST_VERSION="1.2.0"
49+
export ORG_HYPERLEDGER_FABRIC_SDKTEST_VERSION="1.3.0"
5050
#everything just defaults for latest (v1.1)
5151
export ORG_HYPERLEDGER_FABRIC_SDKTEST_ITSUITE=""
5252
#unset to use what's in docker's .env file.

src/test/java/org/hyperledger/fabric/sdk/testutils/TestConfig.java

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,27 @@ public boolean isRunningFabricTLS() {
8383
private final boolean runningFabricTLS;
8484
private static final HashMap<String, SampleOrg> sampleOrgs = new HashMap<>();
8585

86+
private static final String ORG_HYPERLEDGER_FABRIC_SDKTEST_VERSION
87+
= System.getenv("ORG_HYPERLEDGER_FABRIC_SDKTEST_VERSION") == null ? "1.3.0" : System.getenv("ORG_HYPERLEDGER_FABRIC_SDKTEST_VERSION");
88+
8689
static {
8790
//set to fake out discovery during testing to local docker see Endpoint.java's createEndpoint method.
8891
System.setProperty("org.hyperledger.fabric.sdk.test.endpoint_remap_discovery_host_name", "localhost"); // for testing only remaps all endpoint names.
8992
}
9093

94+
int[] fabricVersion = new int[3];
95+
9196
private TestConfig() {
97+
98+
final String[] fvs = ORG_HYPERLEDGER_FABRIC_SDKTEST_VERSION.split("\\.");
99+
if (fvs.length != 3) {
100+
throw new AssertionError("Expected environment variable 'ORG_HYPERLEDGER_FABRIC_SDKTEST_VERSION' to be three numbers sperated by dots (1.0.0) but got: " + ORG_HYPERLEDGER_FABRIC_SDKTEST_VERSION);
101+
102+
}
103+
fabricVersion[0] = Integer.parseInt(fvs[0].trim());
104+
fabricVersion[1] = Integer.parseInt(fvs[1].trim());
105+
fabricVersion[2] = Integer.parseInt(fvs[2].trim());
106+
92107
File loadFile;
93108
FileInputStream configProps;
94109

@@ -169,11 +184,14 @@ private TestConfig() {
169184
sampleOrg.addOrdererLocation(nl[0], grpcTLSify(nl[1]));
170185
}
171186

172-
String eventHubNames = sdkProperties.getProperty(INTEGRATIONTESTS_ORG + orgName + ".eventhub_locations");
173-
ps = eventHubNames.split("[ \t]*,[ \t]*");
174-
for (String peer : ps) {
175-
String[] nl = peer.split("[ \t]*@[ \t]*");
176-
sampleOrg.addEventHubLocation(nl[0], grpcTLSify(nl[1]));
187+
if (isFabricVersionBefore("1.3")) { // Eventhubs supported.
188+
189+
String eventHubNames = sdkProperties.getProperty(INTEGRATIONTESTS_ORG + orgName + ".eventhub_locations");
190+
ps = eventHubNames.split("[ \t]*,[ \t]*");
191+
for (String peer : ps) {
192+
String[] nl = peer.split("[ \t]*@[ \t]*");
193+
sampleOrg.addEventHubLocation(nl[0], grpcTLSify(nl[1]));
194+
}
177195
}
178196

179197
sampleOrg.setCALocation(httpTLSify(sdkProperties.getProperty((INTEGRATIONTESTS_ORG + org.getKey() + ".ca_location"))));
@@ -200,6 +218,42 @@ private TestConfig() {
200218

201219
}
202220

221+
public boolean isFabricVersionAtOrAfter(String version) {
222+
223+
final int[] vers = parseVersion(version);
224+
for (int i = 0; i < 3; ++i) {
225+
if (vers[i] > fabricVersion[i]) {
226+
return false;
227+
}
228+
}
229+
return true;
230+
}
231+
232+
public boolean isFabricVersionBefore(String version) {
233+
234+
return !isFabricVersionAtOrAfter(version);
235+
}
236+
237+
private static int[] parseVersion(String version) {
238+
if (null == version || version.isEmpty()) {
239+
throw new AssertionError("Version is bad :" + version);
240+
}
241+
String[] split = version.split("[ \\t]*\\.[ \\t]*");
242+
if (split.length < 1 || split.length > 3) {
243+
throw new AssertionError("Version is bad :" + version);
244+
}
245+
int[] ret = new int[3];
246+
int i = 0;
247+
for (; i < split.length; ++i) {
248+
ret[i] = Integer.parseInt(split[i]);
249+
}
250+
for (; i < 3; ++i) {
251+
ret[i] = 0;
252+
}
253+
return ret;
254+
255+
}
256+
203257
private String grpcTLSify(String location) {
204258
location = location.trim();
205259
Exception e = Utils.checkGrpcUrl(location);
@@ -385,7 +439,7 @@ public File getTestNetworkConfigFileYAML() {
385439
String pname = "src/test/fixture/sdkintegration/network_configs/";
386440
File ret = new File(pname, fname);
387441

388-
if (!"localhost".equals(LOCALHOST)) {
442+
if (!"localhost".equals(LOCALHOST) || isFabricVersionAtOrAfter("1.3")) {
389443
// change on the fly ...
390444
File temp = null;
391445

@@ -406,6 +460,11 @@ public File getTestNetworkConfigFileYAML() {
406460
sourceText = sourceText.replaceAll("grpcs://localhost", "grpcs://" + LOCALHOST);
407461
sourceText = sourceText.replaceAll("grpc://localhost", "grpc://" + LOCALHOST);
408462

463+
if (isFabricVersionAtOrAfter("1.3")) {
464+
//eventUrl: grpc://localhost:8053
465+
sourceText = sourceText.replaceAll("(?m)^[ \\t]*eventUrl:", "# eventUrl:");
466+
}
467+
409468
Files.write(Paths.get(temp.getAbsolutePath()), sourceText.getBytes(StandardCharsets.UTF_8),
410469
StandardOpenOption.CREATE_NEW, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
411470

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ private Channel reconstructChannel(String name, HFClient client, SampleOrg sampl
608608
assertFalse(newChannel.getPeers(PeerRole.NO_EVENT_SOURCE).isEmpty());
609609

610610
}
611-
assertEquals(2, newChannel.getEventHubs().size());
611+
assertEquals(testConfig.isFabricVersionAtOrAfter("1.3") ? 0 : 2, newChannel.getEventHubs().size());
612612
out("Retrieved channel %s from sample store.", name);
613613

614614
} else {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,17 +846,22 @@ Channel constructChannel(String name, HFClient client, SampleOrg sampleOrg) thro
846846
peerProperties.put("grpc.NettyChannelBuilderOption.maxInboundMessageSize", 9000000);
847847

848848
Peer peer = client.newPeer(peerName, peerLocation, peerProperties);
849-
if (doPeerEventing && everyother) {
849+
if (testConfig.isFabricVersionAtOrAfter("1.3")) {
850850
newChannel.joinPeer(peer, createPeerOptions().setPeerRoles(EnumSet.of(PeerRole.ENDORSING_PEER, PeerRole.LEDGER_QUERY, PeerRole.CHAINCODE_QUERY, PeerRole.EVENT_SOURCE))); //Default is all roles.
851+
851852
} else {
852-
// Set peer to not be all roles but eventing.
853-
newChannel.joinPeer(peer, createPeerOptions().setPeerRoles(EnumSet.of(PeerRole.ENDORSING_PEER, PeerRole.LEDGER_QUERY, PeerRole.CHAINCODE_QUERY)));
853+
if (doPeerEventing && everyother) {
854+
newChannel.joinPeer(peer, createPeerOptions().setPeerRoles(EnumSet.of(PeerRole.ENDORSING_PEER, PeerRole.LEDGER_QUERY, PeerRole.CHAINCODE_QUERY, PeerRole.EVENT_SOURCE))); //Default is all roles.
855+
} else {
856+
// Set peer to not be all roles but eventing.
857+
newChannel.joinPeer(peer, createPeerOptions().setPeerRoles(EnumSet.of(PeerRole.ENDORSING_PEER, PeerRole.LEDGER_QUERY, PeerRole.CHAINCODE_QUERY)));
858+
}
854859
}
855860
out("Peer %s joined channel %s", peerName, name);
856861
everyother = !everyother;
857862
}
858863
//just for testing ...
859-
if (doPeerEventing) {
864+
if (doPeerEventing || testConfig.isFabricVersionAtOrAfter("1.3")) {
860865
// Make sure there is one of each type peer at the very least.
861866
assertFalse(newChannel.getPeers(EnumSet.of(PeerRole.EVENT_SOURCE)).isEmpty());
862867
assertFalse(newChannel.getPeers(PeerRole.NO_EVENT_SOURCE).isEmpty());

0 commit comments

Comments
 (0)