Skip to content

Commit 3f9d2d0

Browse files
committed
add nepune Java tests
1 parent f502fff commit 3f9d2d0

File tree

7 files changed

+942
-244
lines changed

7 files changed

+942
-244
lines changed

javav2/example_code/neptune/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
<groupId>software.amazon.awssdk</groupId>
6969
<artifactId>neptune</artifactId>
7070
</dependency>
71+
<dependency>
72+
<groupId>software.amazon.awssdk</groupId>
73+
<artifactId>netty-nio-client</artifactId>
74+
</dependency>
7175
<dependency>
7276
<groupId>software.amazon.awssdk</groupId>
7377
<artifactId>ec2</artifactId>

javav2/example_code/neptune/src/main/java/com/example/neptune/scenerio/NeptuneActions.java

Lines changed: 439 additions & 188 deletions
Large diffs are not rendered by default.

javav2/example_code/neptune/src/main/java/com/example/neptune/scenerio/NeptuneScenario.java

Lines changed: 70 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33

44
package com.example.neptune.scenerio;
55

6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
69
import java.util.Scanner;
710

811
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
912
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
1013
public class NeptuneScenario {
1114
public static final String DASHES = new String(new char[80]).replace("\0", "-");
12-
15+
private static final Logger logger = LoggerFactory.getLogger(NeptuneScenario.class);
1316
static Scanner scanner = new Scanner(System.in);
1417
static NeptuneActions neptuneActions = new NeptuneActions();
1518

1619
public static void main(String[] args) {
17-
String subnetGroupName = "neptuneSubnetGroup28" ;
20+
String subnetGroupName = "neptuneSubnetGroup56" ;
1821
String vpcId = "vpc-e97a4393" ;
19-
String clusterName = "neptuneCluster28" ;
20-
String dbInstanceId = "neptuneDB28" ;
22+
String clusterName = "neptuneCluster56" ;
23+
String dbInstanceId = "neptuneDB56" ;
2124

22-
System.out.println("""
25+
logger.info("""
2326
Amazon Neptune is a fully managed graph
2427
database service by AWS, designed specifically
2528
for handling complex relationships and connected
@@ -50,98 +53,109 @@ property graphs (via openCypher and Gremlin) and RDF
5053
}
5154

5255
public static void runScenario(String subnetGroupName, String vpcId, String dbInstanceId, String clusterName) {
53-
System.out.println(DASHES);
54-
System.out.println("1. Create a Neptune DB Subnet Group");
55-
System.out.println("The Neptune DB subnet group is used when launching a Neptune cluster");
56+
logger.info(DASHES);
57+
logger.info("1. Create a Neptune DB Subnet Group");
58+
logger.info("The Neptune DB subnet group is used when launching a Neptune cluster");
5659
waitForInputToContinue(scanner);
57-
String groupARN = neptuneActions.createSubnetGroup(vpcId, subnetGroupName);
60+
neptuneActions.createSubnetGroupAsync(vpcId, subnetGroupName).join();
5861
waitForInputToContinue(scanner);
59-
System.out.println(DASHES);
62+
logger.info(DASHES);
6063

61-
System.out.println(DASHES);
62-
System.out.println("2. Create a Neptune Cluster");
63-
System.out.println("A Neptune Cluster allows you to store and query highly connected datasets with low latency.");
64+
logger.info(DASHES);
65+
logger.info("2. Create a Neptune Cluster");
66+
logger.info("A Neptune Cluster allows you to store and query highly connected datasets with low latency.");
6467
waitForInputToContinue(scanner);
65-
String dbClusterId = neptuneActions.createDBCluster(clusterName);
68+
String dbClusterId = neptuneActions.createDBClusterAsync(clusterName).join();
6669
waitForInputToContinue(scanner);
67-
System.out.println(DASHES);
70+
logger.info(DASHES);
6871

69-
System.out.println(DASHES);
70-
System.out.println("3. Create a Neptune DB Instance");
71-
System.out.println("In this step, we add a new database instance to the Neptune cluster");
72+
logger.info(DASHES);
73+
logger.info("3. Create a Neptune DB Instance");
74+
logger.info("In this step, we add a new database instance to the Neptune cluster");
7275
waitForInputToContinue(scanner);
73-
neptuneActions.createDBInstance(dbInstanceId, dbClusterId);
76+
neptuneActions.createDBInstanceAsync(dbInstanceId, dbClusterId).join();
7477
waitForInputToContinue(scanner);
75-
System.out.println(DASHES);
78+
logger.info(DASHES);
7679

77-
System.out.println(DASHES);
78-
System.out.println("4. Check the status of the Neptune DB Instance");
79-
System.out.println("""
80+
logger.info(DASHES);
81+
logger.info("4. Check the status of the Neptune DB Instance");
82+
logger.info("""
8083
In this step, we will wait until the DB instance
8184
becomes available. This may take around 10 minutes.
8285
""");
8386
waitForInputToContinue(scanner);
84-
neptuneActions.isNeptuneInstanceReady(dbInstanceId);
87+
neptuneActions.checkInstanceStatus(dbInstanceId, "available").join();
8588
waitForInputToContinue(scanner);
86-
System.out.println(DASHES);
89+
logger.info(DASHES);
8790

88-
System.out.println(DASHES);
89-
System.out.println("5. Tag the Amazon Neptune Resource");
91+
logger.info(DASHES);
92+
logger.info("5.Show Neptune Cluster details");
9093
waitForInputToContinue(scanner);
91-
System.out.println(DASHES);
92-
93-
System.out.println(DASHES);
94-
System.out.println("6.Show Neptune Cluster details");
94+
neptuneActions.describeDBClustersAsync(clusterName).join();
9595
waitForInputToContinue(scanner);
96-
neptuneActions.describeDBClusters(clusterName);
96+
logger.info(DASHES);
97+
98+
logger.info(DASHES);
99+
logger.info("6. Stop the Amazon Neptune cluster");
100+
logger.info("""
101+
Once stopped, this step polls the status
102+
until the cluster is in a stopped state.
103+
""");
97104
waitForInputToContinue(scanner);
98-
System.out.println(DASHES);
99-
100-
System.out.println(DASHES);
101-
System.out.println("7.Show Neptune Instance details");
105+
neptuneActions.stopDBCluster(dbClusterId);
106+
neptuneActions.waitForClusterStatus(dbClusterId,"stopped");
102107
waitForInputToContinue(scanner);
103-
neptuneActions.describeDBInstances(dbInstanceId);
108+
logger.info(DASHES);
109+
110+
logger.info(DASHES);
111+
logger.info("7. Start the Amazon Neptune cluster");
112+
logger.info("""
113+
Once started, this step polls the clusters
114+
status until it's in an available state.
115+
We will also poll the instance status.
116+
""");
104117
waitForInputToContinue(scanner);
105-
System.out.println(DASHES);
106-
107-
System.out.println(DASHES);
108-
System.out.println("8. Delete the Neptune Assets");
109-
System.out.println("Would you like to delete the Neptune Assets? (y/n)");
118+
neptuneActions.startDBCluster(dbClusterId);
119+
neptuneActions.waitForClusterStatus(dbClusterId,"available");
120+
neptuneActions.checkInstanceStatus(dbInstanceId, "available").join();
121+
logger.info(DASHES);
122+
logger.info(DASHES);
123+
logger.info("8. Delete the Neptune Assets");
124+
logger.info("Would you like to delete the Neptune Assets? (y/n)");
110125
String delAns = scanner.nextLine().trim();
111126
if (delAns.equalsIgnoreCase("y")) {
112-
System.out.println("You selected to delete the Neptune assets.");
113-
neptuneActions.deleteDBInstance(dbInstanceId);
114-
neptuneActions.deleteDBCluster(dbClusterId);
115-
neptuneActions.deleteDBSubnetGroup(subnetGroupName);
127+
logger.info("You selected to delete the Neptune assets.");
128+
neptuneActions.deleteNeptuneResourcesAsync(dbInstanceId, clusterName, subnetGroupName);
129+
116130
} else {
117-
System.out.println("You selected not to delete Neptune assets.");
131+
logger.info("You selected not to delete Neptune assets.");
118132
}
119133
waitForInputToContinue(scanner);
120-
System.out.println(DASHES);
134+
logger.info(DASHES);
121135

122-
System.out.println(DASHES);
123-
System.out.println(
136+
logger.info(DASHES);
137+
logger.info(
124138
"""
125139
Thank you for checking out the Amazon Neptune Service Use demo. We hope you
126140
learned something new, or got some inspiration for your own apps today.
127141
For more AWS code examples, have a look at:
128142
https://docs.aws.amazon.com/code-library/latest/ug/what-is-code-library.html
129143
""");
130-
System.out.println(DASHES);
144+
logger.info(DASHES);
131145
}
132146

133147
private static void waitForInputToContinue(Scanner scanner) {
134148
while (true) {
135-
System.out.println("");
136-
System.out.println("Enter 'c' followed by <ENTER> to continue:");
149+
logger.info("");
150+
logger.info("Enter 'c' followed by <ENTER> to continue:");
137151
String input = scanner.nextLine();
138152

139153
if (input.trim().equalsIgnoreCase("c")) {
140-
System.out.println("Continuing with the program...");
141-
System.out.println("");
154+
logger.info("Continuing with the program...");
155+
logger.info("");
142156
break;
143157
} else {
144-
System.out.println("Invalid input. Please try again.");
158+
logger.info("Invalid input. Please try again.");
145159
}
146160
}
147161
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Configuration status="WARN">
2+
<Appenders>
3+
<Console name="ConsoleAppender" target="SYSTEM_OUT">
4+
<PatternLayout pattern="%msg%n"/>
5+
</Console>
6+
<Console name="AlignedConsoleAppender" target="SYSTEM_OUT">
7+
<PatternLayout pattern="%m%n"/>
8+
</Console>
9+
</Appenders>
10+
<Loggers>
11+
<!-- Root logger configuration -->
12+
<Root level="info">
13+
<!-- Specify which appenders to use -->
14+
<AppenderRef ref="ConsoleAppender" />
15+
</Root>
16+
</Loggers>
17+
</Configuration>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import com.example.neptune.scenerio.NeptuneActions;
5+
import org.junit.jupiter.api.MethodOrderer;
6+
import org.junit.jupiter.api.Order;
7+
import org.junit.jupiter.api.Tag;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.TestInstance;
10+
import org.junit.jupiter.api.TestMethodOrder;
11+
12+
import static org.junit.jupiter.api.Assertions.*;
13+
14+
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
15+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
16+
public class NeptuneTest {
17+
private static String subnetGroupName = "neptuneSubnetGroupTest" ;
18+
private static String vpcId = "vpc-e97a4393" ;
19+
private static String clusterName = "neptuneClusterTest" ;
20+
private static String dbInstanceId = "neptuneDBTest" ;
21+
private static NeptuneActions neptuneActions = new NeptuneActions();
22+
private static String dbClusterId = "";
23+
24+
@Test
25+
@Tag("IntegrationTest")
26+
@Order(1)
27+
public void testCreateSubnetGroup() {
28+
assertDoesNotThrow(() -> {
29+
neptuneActions.createSubnetGroupAsync(vpcId, subnetGroupName).join();
30+
//assertTrue(signalCatalogArn.startsWith("arn:"), "The ARN should start with 'arn:'");
31+
});
32+
System.out.println("Test 1 passed");
33+
}
34+
35+
@Test
36+
@Tag("IntegrationTest")
37+
@Order(2)
38+
public void testCreateCluster() {
39+
assertDoesNotThrow(() -> {
40+
dbClusterId = neptuneActions.createDBClusterAsync(clusterName).join();
41+
assertFalse(dbClusterId.trim().isEmpty(), "DB Cluster ID should not be empty");
42+
});
43+
System.out.println("Test 2 passed");
44+
}
45+
46+
@Test
47+
@Tag("IntegrationTest")
48+
@Order(3)
49+
public void testCreateDBInstance() {
50+
assertDoesNotThrow(() -> {
51+
neptuneActions.createDBInstanceAsync(dbInstanceId, dbClusterId).join();
52+
});
53+
System.out.println("Test 3 passed");
54+
}
55+
56+
@Test
57+
@Tag("IntegrationTest")
58+
@Order(4)
59+
public void testCheckInstance() {
60+
assertDoesNotThrow(() -> {
61+
neptuneActions.checkInstanceStatus(dbInstanceId, "available").join();
62+
});
63+
System.out.println("Test 4 passed");
64+
}
65+
66+
@Test
67+
@Tag("IntegrationTest")
68+
@Order(5)
69+
public void testDescribeDBCluster() {
70+
assertDoesNotThrow(() -> {
71+
neptuneActions.describeDBClustersAsync(clusterName).join();
72+
});
73+
System.out.println("Test 5 passed");
74+
}
75+
76+
@Test
77+
@Tag("IntegrationTest")
78+
@Order(6)
79+
public void testStopDBCluster() {
80+
assertDoesNotThrow(() -> {
81+
neptuneActions.stopDBCluster(dbClusterId);
82+
neptuneActions.waitForClusterStatus(dbClusterId,"stopped");
83+
});
84+
System.out.println("Test 6 passed");
85+
}
86+
87+
@Test
88+
@Tag("IntegrationTest")
89+
@Order(7)
90+
public void testStartDBCluster() {
91+
assertDoesNotThrow(() -> {
92+
neptuneActions.startDBCluster(dbClusterId);
93+
neptuneActions.waitForClusterStatus(dbClusterId,"available");
94+
neptuneActions.checkInstanceStatus(dbInstanceId, "available").join();
95+
});
96+
System.out.println("Test 7 passed");
97+
}
98+
99+
@Test
100+
@Tag("IntegrationTest")
101+
@Order(8)
102+
public void testDeleteResources() {
103+
assertDoesNotThrow(() -> {
104+
neptuneActions.deleteNeptuneResourcesAsync(dbInstanceId, clusterName, subnetGroupName);
105+
});
106+
System.out.println("Test 8 passed");
107+
}
108+
}

scenarios/basics/neptune/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Overview
2+
This AWS IoT Fleetwise basic scenario demonstrates how to interact with the AWS IoT FleetWise service using an AWS SDK. The scenario covers various operations such as creating a collection of standardized signals, creating a model manifest, creating a vehicle, and so on.
3+
4+
## Key Operations
5+
6+
1. **Create an AWS Fleetwise signal catalog**:
7+
- This step creates an AWS Fleetwise signal catalog by invoking the `createSignalCatalog`method.
8+
9+
2. **Create an AWS IoT Fleetwise fleet**:
10+
- This operation creates an AWS Fleetwise fleet by invoking the `createFleet`method.
11+
12+
3. **Create a model manifest**:
13+
- This operation creates an AWS Fleetwise model manifest by invoking the `createModelManifest`method.
14+
15+
4. **Create a decoder manifest**:
16+
- This operation creates an AWS Fleetwise decoder manifest by invoking the `createDecoderManifest`method.
17+
18+
5. **Create a vehicle**:
19+
- This operation creates an AWS Fleetwise vehicle by invoking the `createVehicle`method.
20+
21+
**Note** See the [Engineering specification](SPECIFICATION.md) for a full listing of operations.
22+
23+
## Resources
24+
25+
This Basics scenario does not require any additional AWS resources.
26+
27+
## Implementations
28+
29+
This scenario example will be implemented in the following languages:
30+
31+
- Java
32+
- JavaScript
33+
- Kotlin
34+
35+
## Additional Reading
36+
37+
- [AWS IoT Fleetwise Documentation](https://docs.aws.amazon.com/iot-fleetwise/latest/developerguide/what-is-iotfleetwise.html)
38+
39+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

0 commit comments

Comments
 (0)