Skip to content

Commit

Permalink
Add example test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hoang-ho committed Mar 15, 2021
1 parent 2bce1dd commit 5aa86c6
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 47 deletions.
31 changes: 31 additions & 0 deletions TestCase2EC2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"N": "3",
"K": "1",
"network": [
{
"id": "0",
"IPAddress": "172.31.45.247",
"port": "8080",
"neighbors": [
"2"
]
},
{
"id": "1",
"IPAddress": "172.31.91.178",
"port": "8080",
"neighbors": [
"2"
]
},
{
"id": "2",
"IPAddress": "172.31.88.28",
"port": "8080",
"neighbors": [
"0",
"1"
]
}
]
}
61 changes: 61 additions & 0 deletions TestCase3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"N": "7",
"K": "3",
"network": [
{
"id": "0",
"IPAddress": "localhost",
"port": "8080",
"neighbors": [
"3",
"1"
]
},
{
"id": "1",
"IPAddress": "localhost",
"port": "8081",
"neighbors": [
"0",
"3"
]
},
{
"id": "2",
"IPAddress": "localhost",
"port": "8082",
"neighbors": [
"1",
"4"
]
},
{
"id": "3",
"IPAddress": "localhost",
"port": "8083",
"neighbors": [
"0",
"2",
"5"
]
},
{
"id": "4",
"IPAddress": "localhost",
"port": "8084",
"neighbors": [
"2",
"6"
]
},
{
"id": "5",
"IPAddress": "localhost",
"port": "8085",
"neighbors": [
"3",
"6"
]
}
]
}
9 changes: 9 additions & 0 deletions doc/test/TestCase1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
echo "This script is to run TestCase1 on one single machine"

echo "We will run two processes in parallel in this test script"

# Start the Buyer
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase1.json -id 0 -role buyer -product fish -hop 1 &

# Start the Seller
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase1.json -id 1 -role seller -product fish -stock 1 &
11 changes: 11 additions & 0 deletions doc/test/TestCase2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
echo "This script is to run TestCase2 on one single machine"

echo "We will run two processes in parallel in this test script"

# Start the Buyer
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 0 -role buyer -product fish -hop 1 &

java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 1 -role buyer -product fish -hop 1 &

# Start the Seller
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 2 -role seller -product fish -stock 1 &
21 changes: 21 additions & 0 deletions doc/test/TestCase3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
echo "This script is to run TestCase3 on one single machine"

echo "We will run two processes in parallel in this test script"

# Start the Buyer
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 0 -role buyer -product boar -hop 4 &

java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 1 -role buyer -product boar -hop 3 &

java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 2 -role buyer -product fish -hop 3 &

# start the no-role peer

java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 3 -role peer &

java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 4 -role peer &

# Start the Seller
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 5 -role seller -product boar -stock 3 &

java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 6 -role seller -product fish -stock 3 &
34 changes: 0 additions & 34 deletions doc/test/test.sh

This file was deleted.

71 changes: 62 additions & 9 deletions doc/testVerify.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,82 @@

### Milestone 3

Steps to run EC2
**Steps to run locally**

Example for config files are TestCase1.json and TestCase2.json.

To run locally on your computer, for each test case with config file TestCase1.json/TestCase2.json/TestCase3.json,
open up N terminals (where N is the number of peers specified in each test case). In each terminal, decides which id, which role you want the node to take.
For Buyer and Seller, you will also need to specify the product you want the peer to start with, for Seller, you will also need to specify stock and for Buyer, you will also need to specify HopCount

Example:
For **TestCase1.json**, we can specify the buyer as:

```
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase1.json -id 0 -role buyer -product fish -hop 1
```

and the seller as:
```
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase1.json -id 1 -role seller -product fish -stock 1
```

The test script for this test case is in doc/test/TestCase1.sh, which will run 2 processes in parallel


For **TestCase2.json**, let node 0 and 1 be the buyer and node 2 be the seller, we can specify the buyer as:

```
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 0 -role buyer -product fish -hop 1
```

```
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 1 -role buyer -product fish -hop 1
```

and the seller as:
```
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 2 -role seller -product fish -stock 1
```

The test script for this test case is in doc/test/TestCase2.sh, which will run 3 processes in parallel

For each test case, repeatedly do the following:

1. Create the instance
For **TestCase3.json**, let node 0, 1, 2 be the buyer, and node 3 and 4 be the no-role peer, and node 5 and 6 be the seller.
Open up 7 terminals and try the following:

```
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 0 -role buyer -product boar -hop 4
```

```
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 1 -role buyer -product boar -hop 3
```

```
aws ec2 run-instances --image-id ami-07916b33d72291f85 --instance-type t2.micro --key-name 677kp
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 2 -role buyer -product fish -hop 3
```

2. From the terminal output, obtain the InstanceId and PrivateIpAddress. Replace the placeholder in TestCase1.txt with corresponding PrivateIpAddress

```
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 3 -role peer
```

```
aws ec2 describe-instances --instance-id $InstanceId
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 4 -role peer
```

Get the instance id from the terminal output and run
```
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 5 -role seller -product boar -stock 3
```

```
ssh -i "677kp.pem" ec2-user@
java -jar build/libs/BuyerSellerNetwork-1.0-SNAPSHOT.jar -config TestCase2.json -id 6 -role seller -product fish -stock 3
```

The test script for this test case is in doc/test/TestCase3.sh, which will run 7 processes in parallel

Steps to run EC2



### Milestone 2
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/p2p/Runner.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.p2p;

import com.google.gson.JsonParser;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import com.p2p.grpc.Buyer;
import com.p2p.grpc.PeerId;
import com.p2p.grpc.PeerImpl;
import com.p2p.grpc.Product;
import com.p2p.grpc.Seller;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

Expand All @@ -20,11 +19,12 @@ public class Runner {
static final String ID = "-id";
static final String PRODUCT = "-product";
static final String STOCK = "-stock";
static final String HOP = "-hop";

public static void main(String[] args) throws IOException, ParseException {
// Read the config file and start running on EC2
String configFile = "", role = "", id = "", product = "FISH";
int stock = 1;
int stock = 1, hop = 1;
for (int i = 0; i < args.length; i++) {
if (args[i].equals(CONFIG)) {
i++;
Expand All @@ -41,6 +41,9 @@ public static void main(String[] args) throws IOException, ParseException {
} else if (args[i].equals(STOCK)) {
i++;
stock = Integer.parseInt(args[i]);
} else if (args[i].equals(HOP)) {
i++;
hop = Integer.parseInt(args[i]);
}
}

Expand All @@ -54,6 +57,7 @@ public static void main(String[] args) throws IOException, ParseException {
// Create a buyer
peer = new Buyer(Integer.parseInt(id), (String) nodeConfig.get("IPAddress"),
Integer.parseInt((String) nodeConfig.get("port")), neighbors.size(), Product.valueOf(product));
((Buyer) peer).setHopCount(hop);

} else if (role.toLowerCase().equals("seller")) {
peer = new Seller(Integer.parseInt(id), (String) nodeConfig.get("IPAddress"),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/p2p/grpc/Buyer.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,5 @@ public void setProduct(String product) {
this.product = Product.valueOf(product.toUpperCase());
}

public void setHopCount(int hop) {this.hopCount = hop; }
}

0 comments on commit 5aa86c6

Please sign in to comment.