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

Commit c799c52

Browse files
committed
FABJ-422 Allow test to change node cc version used.
Change-Id: Ie528ca7c98aed24e9c1d952e00b9df20fe5488ec Signed-off-by: rickr <cr22rc@gmail.com>
1 parent dbc41c1 commit c799c52

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ The SDK's defaults are all in the file [Config.java](https://github.com/hyperled
288288
The [config.properties](https://github.com/hyperledger/fabric-sdk-java/blob/a2140f9bba57a63c58d9ee8579fea7164bf3beb2/config.properties)
289289
also has some descriptions on what they do. Most server timeout request can be overridden with the specific request too.
290290

291+
### What's difference between joining and adding a peer to a channel?
292+
You only ever *join* a peer belonging to _your own organization_ to a channel once at the beginning. You would only *add* peers
293+
from other organizations or peers of your own organization you've already *joined* like when recreating the channel SDK object.
294+
291295
### java.security.InvalidKeyException: Illegal key size
292296

293297
If you get this error, this means your JDK does not capable of handling unlimited strength crypto algorithms. To fix this issue, You will need to download the JCE libraries for your version of JDK. Please follow the instructions <a href="http://stackoverflow.com/questions/6481627/java-security-illegal-key-size-or-default-parameters">here</a> to download and install the JCE for your version of the JDK.

src/test/fixture/sdkintegration/nodecc/sample1/package.json renamed to src/test/fixture/sdkintegration/nodecc/sample1/package.json.TEMPLATE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This template will get modified by TestConfig.java and renamed to package.json
12
{
23
"name": "example_cc",
34
"version": "1.0.0",
@@ -13,6 +14,6 @@
1314
},
1415
"license": "Apache-2.0",
1516
"dependencies": {
16-
"fabric-shim": "~1.4.0"
17+
"fabric-shim": ${1}
1718
}
1819
}

src/test/fixture/sdkintegration/nodecc/sample_11/package.json renamed to src/test/fixture/sdkintegration/nodecc/sample_11/package.json.TEMPLATE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This template will get modified by TestConfig.java and renamed to package.json
12
{
23
"name": "example_cc",
34
"version": "1.0.0",
@@ -13,6 +14,6 @@
1314
},
1415
"license": "Apache-2.0",
1516
"dependencies": {
16-
"fabric-shim": "~1.4.0"
17+
"fabric-shim": ${1}
1718
}
1819
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@
1818
import java.io.IOException;
1919
import java.nio.charset.StandardCharsets;
2020
import java.nio.file.Files;
21+
import java.nio.file.Path;
2122
import java.nio.file.Paths;
2223
import java.nio.file.StandardOpenOption;
2324
import java.util.Collection;
2425
import java.util.Collections;
2526
import java.util.HashMap;
27+
import java.util.List;
2628
import java.util.Map;
2729
import java.util.Objects;
2830
import java.util.Properties;
2931
import java.util.regex.Matcher;
3032
import java.util.regex.Pattern;
33+
import java.util.stream.Collectors;
34+
import java.util.stream.Stream;
3135

3236
import org.apache.commons.logging.Log;
3337
import org.apache.commons.logging.LogFactory;
@@ -207,6 +211,29 @@ private TestConfig() {
207211

208212
sampleOrg.setCAProperties(properties);
209213
}
214+
215+
//FIX Node chaincode to reference chaincode shim package according to fabric version.
216+
217+
String ncCv = 2 == fabricVersion[0] ? "\"unstable\"" : String.format("\"~%d.%d.0\"", fabricVersion[0], fabricVersion[1]);
218+
219+
try {
220+
List<Path> collect = null;
221+
try (Stream<Path> filess = Files.walk(Paths.get("src/test/fixture/sdkintegration/nodecc"))) {
222+
collect = filess.filter(f -> f.getFileName().toString().equals("package.json.TEMPLATE"))
223+
.collect(Collectors.toList());
224+
}
225+
226+
for (Path jspf : collect) {
227+
String jpff = new String(Files.readAllBytes(jspf)).replaceAll(Pattern.quote("${1}"), ncCv).replaceAll("(?m)^#.*$\n", "");
228+
Path pkgjson = Paths.get(jspf.getParent().toFile().getAbsolutePath(), "package.json");
229+
pkgjson.toFile().deleteOnExit();
230+
Files.write(pkgjson, jpff.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
231+
}
232+
233+
} catch (Exception e) {
234+
throw new RuntimeException(e);
235+
}
236+
210237
}
211238

212239
}

0 commit comments

Comments
 (0)