Skip to content

Commit

Permalink
Table implementation in java shim with example
Browse files Browse the repository at this point in the history
This will fix issue FAB-215
https://jira.hyperledger.org/browse/FAB-215

Change-Id: I2cfcd4b08596195e3acaff97db8b8234a899cad1
Signed-off-by: Satheesh Kathamuthu <satheesh.ceg@gmail.com>
  • Loading branch information
xspeedcruiser committed Oct 31, 2016
1 parent 18a44d0 commit c5356ac
Show file tree
Hide file tree
Showing 9 changed files with 784 additions and 589 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ build/image/ccenv/.dummy: build/image/ccenv/bin/protoc-gen-go build/image/ccenv/
@touch $@

# Special override for java-image
# Following items are packed and sent to docker context while building image
# 1. Java shim layer source code
# 2. Proto files used to generate java classes
# 3. Gradle settings file
build/image/javaenv/.dummy: Makefile $(JAVASHIM_DEPS)
@echo "Building docker javaenv-image"
@mkdir -p $(@D)
Expand All @@ -214,7 +218,7 @@ build/image/javaenv/.dummy: Makefile $(JAVASHIM_DEPS)
# 2. Proto files used to generate java classes
# 3. Gradle settings file
@git ls-files core/chaincode/shim/java | tar -jcT - > $(@D)/javashimsrc.tar.bz2
@git ls-files protos settings.gradle | tar -jcT - > $(@D)/protos.tar.bz2
@git ls-files protos core/chaincode/shim/table.proto settings.gradle | tar -jcT - > $(@D)/protos.tar.bz2
docker build -t $(PROJECT_NAME)-javaenv $(@D)
docker tag $(PROJECT_NAME)-javaenv $(PROJECT_NAME)-javaenv:$(DOCKER_TAG)
@touch $@
Expand Down
93 changes: 74 additions & 19 deletions bddtests/java_shim.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,43 @@

#@chaincodeImagesUpToDate
@preV1
Feature: SimpleSample Java example

Feature: Java chaincode example
Scenario: java SimpleSample chaincode example single peer
Given we compose "docker-compose-1.yml"
When requesting "/chain" from "vp0"
Then I should get a JSON response with "height" = "1"
When I deploy lang chaincode "examples/chaincode/java/SimpleSample" of "JAVA" with ctor "init" to "vp0"
| arg1 | arg2 | arg3 | arg4 |
| a | 100 | b | 200 |
Then I should have received a chaincode name
Then I wait up to "300" seconds for transaction to be committed to all peers
When I deploy lang chaincode "examples/chaincode/java/SimpleSample" of "JAVA" with ctor "init" to "vp0"
| arg1 | arg2 | arg3 | arg4 |
| a | 100 | b | 200 |
Then I should have received a chaincode name
Then I wait up to "300" seconds for transaction to be committed to all peers

When requesting "/chain" from "vp0"
Then I should get a JSON response with "height" = "2"
When requesting "/chain" from "vp0"
Then I should get a JSON response with "height" = "2"

When I query chaincode "SimpleSample" function name "query" on "vp0":
|arg1|
| a |
Then I should get a JSON response with "result.message" = "{'Name':'a','Amount':'100'}"
Then I should get a JSON response with "result.message" = "{'Name':'a','Amount':'100'}"

When I invoke chaincode "SimpleSample" function name "transfer" on "vp0"
|arg1|arg2|arg3|
| a | b | 10 |
Then I should have received a transactionID
Then I wait up to "25" seconds for transaction to be committed to all peers
|arg1|arg2|arg3|
| a | b | 10 |
Then I should have received a transactionID
Then I wait up to "25" seconds for transaction to be committed to all peers

When requesting "/chain" from "vp0"
Then I should get a JSON response with "height" = "3"
When requesting "/chain" from "vp0"
Then I should get a JSON response with "height" = "3"

When I query chaincode "SimpleSample" function name "query" on "vp0":
|arg1|
| a |
Then I should get a JSON response with "result.message" = "{'Name':'a','Amount':'90'}"
Then I should get a JSON response with "result.message" = "{'Name':'a','Amount':'90'}"

When I query chaincode "SimpleSample" function name "query" on "vp0":
|arg1|
| b |
Then I should get a JSON response with "result.message" = "{'Name':'b','Amount':'210'}"
Then I should get a JSON response with "result.message" = "{'Name':'b','Amount':'210'}"

Scenario: java RangeExample chaincode single peer
Given we compose "docker-compose-1.yml"
Expand Down Expand Up @@ -117,4 +116,60 @@ Scenario: java RangeExample chaincode single peer
When I query chaincode "RangeExample" function name "keys" on "vp0":
||
||
Then I should get a JSON response with "result.message" = "[a]"
Then I should get a JSON response with "result.message" = "[a]"

Scenario: Java TableExample chaincode single peer
Given we compose "docker-compose-1.yml"
When requesting "/chain" from "vp0"
Then I should get a JSON response with "height" = "1"
When I deploy lang chaincode "examples/chaincode/java/TableExample" of "JAVA" with ctor "init" to "vp0"
||
||
Then I should have received a chaincode name
Then I wait up to "30" seconds for transaction to be committed to all peers

When requesting "/chain" from "vp0"
Then I should get a JSON response with "height" = "2"
When I invoke chaincode "TableExample" function name "insert" on "vp0"
|arg1|arg2|
| 0 | Alice |
Then I should have received a transactionID
Then I wait up to "25" seconds for transaction to be committed to all peers
When I invoke chaincode "TableExample" function name "insert" on "vp0"
|arg1|arg2|
| 1 | Bob |
Then I should have received a transactionID
Then I wait up to "25" seconds for transaction to be committed to all peers
When I invoke chaincode "TableExample" function name "insert" on "vp0"
|arg1|arg2|
| 2 | Charlie |
Then I should have received a transactionID
Then I wait up to "25" seconds for transaction to be committed to all peers

When I query chaincode "TableExample" function name "get" on "vp0":
|arg1|
| 0 |
Then I should get a JSON response with "result.message" = "Alice"

When I query chaincode "TableExample" function name "get" on "vp0":
|arg1|
| 2 |
Then I should get a JSON response with "result.message" = "Charlie"
When I invoke chaincode "TableExample" function name "update" on "vp0"
|arg1|arg2|
| 2 | Chaitra |
Then I should have received a transactionID
Then I wait up to "25" seconds for transaction to be committed to all peers
When I query chaincode "TableExample" function name "get" on "vp0":
|arg1|
| 2 |
Then I should get a JSON response with "result.message" = "Chaitra"
When I invoke chaincode "TableExample" function name "delete" on "vp0"
|arg1|
| 2 |
Then I should have received a transactionID
Then I wait up to "25" seconds for transaction to be committed to all peers
When I query chaincode "TableExample" function name "get" on "vp0":
|arg1|
| 2 |
Then I should get a JSON response with "result.message" = "No record found !"
17 changes: 13 additions & 4 deletions core/chaincode/shim/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,21 @@ task copyToLib(type: Copy) {


task copyProtos(type:Copy){
into "${projectDir}/src/main/proto"
from "${rootDir}/protos"
include '**/chaincodeevent.proto'
include '**/chaincode.proto'

from ("${rootDir}/protos"){
include '**/chaincodeevent.proto'
include '**/chaincode.proto'
}
from ("../") {
duplicatesStrategy.EXCLUDE
include '**/table.proto'
exclude 'java'
}
into "${projectDir}/src/main/proto"

}


tasks['build'].mustRunAfter tasks['copyProtos']
build.dependsOn(copyProtos)
build.finalizedBy(copyToLib)
Expand Down

0 comments on commit c5356ac

Please sign in to comment.