Release Note:
- Create new FabricConnection as connection.
- FabricConnection able to query and invoke to target fabric network.
- Defined exception if query or invoke response different between target peers.
- Load configuration from file.
Sample usage:
Gradle
implementation group: 'com.github.samyuan1990', name:'FabricJavaPool', version: '0.0.2'
For SNAPSHOT version
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
implementation group: 'com.github.samyuan1990', name:'FabricJavaPool', version: '0.0.2-SNAPSHOT'
Pool config
Fabric network config file in json format and file path as configNetworkPath.
configNetworkPath=./src/test/resources/Networkconfig.json
maxTotal=10
maxIdle=8
minIdle=2
maxWaitMillis=1000
Get Connection
ObjectPool<FabricConnection> fabricConnectionPool = new FabricJavaPool(TestUtil.getUser(), TestUtil.myChannel);
// By Default it will read pool config from ./resources/FabricJavaPool.properties
try {
FabricConnection fabricConnection = fabricConnectionPool.borrowObject();
FabricConnection fabricConnection2 = fabricConnectionPool.borrowObject();
String rs = fabricConnection.query(TestUtil.chaincodeID, "query", "a");
String rs2 = fabricConnection2.query(TestUtil.chaincodeID, "query", "a");
}
fabricConnectionPool.returnObject(fabricConnection);
fabricConnectionPool.returnObject(fabricConnection2);
} catch (Exception e) {
e.printStackTrace();
}
Make ChainCode
ChaincodeID cci = Util.generateChainCodeID(TestUtil.myCC, TestUtil.myCCVersion);
Query
FabricConnection myConnection = myChannelPool.borrowObject();
ExecuteResult rs = myConnection.query(cci, "query", "a");
Assert.assertEquals("90", rs.getResult());
Invoke
FabricConnection myConnection = myChannelPool.borrowObject();
ExecuteResult rs = myConnection.invoke(cci, "query", "a");
Assert.assertEquals("90", rs.getResult());
Query or Invoke exception
myConnection.invoke(TestUtil.chaincodeID, "error", "a");
} catch (RunTimeException e) {
Assert.assertEquals(ChaincodeResponse.Status.FAILURE, e.getStatus());
Assert.assertEquals(Util.errorHappenDuringQuery, e.getMsg());
Query or Invoke exception due to chaincode results are different on peers
myConnection.query(TestUtil.chaincodeID, "query", "a");
} catch (RunTimeException e) {
Assert.assertEquals(ChaincodeResponse.Status.SUCCESS, e.getStatus());
Assert.assertEquals(Util.resultOnPeersDiff, e.getMsg());
}
Change log:
https://github.com/SamYuan1990/FabricJavaPool/issues/11
https://github.com/SamYuan1990/FabricJavaPool/issues/12
https://github.com/SamYuan1990/FabricJavaPool/issues/13
https://github.com/SamYuan1990/FabricJavaPool/issues/17
Sample project for usage:
https://github.com/SamYuan1990/fabric-java-spring
Latest performance test for Sample project:
Description for the test
Pool without cache:
Label | # Samples | Average | Median | 90% Line | 95% Line | 99% Line | Min | Max | Error % | Throughput | Received KB/sec | Sent KB/sec |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Home Page | 22494 | 25 | 25 | 31 | 33 | 38 | 10 | 112 | 0.000% | 374.80005 | 70.27 | 45.02 |
TOTAL | 22494 | 25 | 25 | 31 | 33 | 38 | 10 | 112 | 0.000% | 374.80005 | 70.27 | 45.02 |