Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Improve test coverage for ovsdb-client module
Browse files Browse the repository at this point in the history
Signed-off-by: Hechao Li <hechaol@outlook.com>
  • Loading branch information
hechaoli committed May 9, 2018
1 parent 98547f0 commit 2c5b089
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public OvsdbClientActiveConnectionTest() {

@After
public void tearDown() {
super.teardown();
passiveOvsdbServer.stopListening().join();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public OvsdbClientPassiveConnectionTest() {

@After
public void tearDown() {
super.teardown();
activeOvsdbServer.disconnect().join();
passiveListener.stopListening(PORT).join();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,19 @@ abstract class OvsdbClientTest {

abstract void setUp(boolean withSsl);

private void testAll() throws IOException, OvsdbClientException {
void teardown() {
ovsdbClient.shutdown();

OvsdbClientException exception = null;
try {
ovsdbClient.listDatabases();
} catch (OvsdbClientException e) {
exception = e;
}
assertNotNull(exception);
}

private void testBasic() throws OvsdbClientException, IOException {
testListDatabases();
testGetSchema();
testInsertTransact();
Expand All @@ -128,7 +140,17 @@ private void testAll() throws IOException, OvsdbClientException {
testConnectionInfo();
testErrorOperation();
testLock();
testEchoResponse();
testEcho();
}

private void testNegative() throws OvsdbClientException, IOException {
testInvalidJsonRpcMessage();
testInvalidMonitorUpdate();
}

private void testAll() throws IOException, OvsdbClientException {
testBasic();
testNegative();
}

void testTcpConnection()
Expand Down Expand Up @@ -437,7 +459,7 @@ private void testCancelMonitor() throws OvsdbClientException {
.monitor("hardware_vtep", monitorId, monitorRequests, monitorCallback);
f.join();

expectedRequest = getJsonRequestString("monitor_cancel", "1");
expectedRequest = getJsonRequestString("monitor_cancel", monitorId);
setupOvsdbEmulator(expectedRequest, "{}", null);
f = ovsdbClient.cancelMonitor(monitorId);
f.join();
Expand Down Expand Up @@ -561,7 +583,7 @@ private void testLock() throws OvsdbClientException {
verify(lockCallback3, timeout(VERIFY_TIMEOUT_MILLIS)).stolen();
}

private void testEchoResponse() {
private void testEcho() {
CompletableFuture<Void> successFuture1 = new CompletableFuture<>();
final String expectedResponse1 = "{\"result\":[]," + "\"error\":null,\"id\":\"echo\"}";
ovsdbServerEmulator.registerReadCallback(msg -> {
Expand Down Expand Up @@ -593,6 +615,20 @@ private void testEchoResponse() {
}
}

private void testInvalidJsonRpcMessage() throws OvsdbClientException, IOException {
// Send an invalid JSON-RPC message
ovsdbServerEmulator.write("{\"method\":\"foo\"}");
// Make sure it still works after receiving this invalid message.
testBasic();
}

private void testInvalidMonitorUpdate() throws OvsdbClientException, IOException {
// Send an invalid monitor update message
ovsdbServerEmulator.write("{\"method\":\"update\", \"params\":[\"blabla\"], \"id\":null}");
// Make sure it still works after processing this invalid message.
testBasic();
}

private void setupOvsdbEmulator(
String request, String result, String error
) {
Expand Down
14 changes: 5 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
Expand Down Expand Up @@ -143,10 +138,6 @@

<dependencies>
<!-- Common dependencies for all modules -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
Expand Down Expand Up @@ -218,6 +209,11 @@
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.plugin.version}</version>
<configuration>
<instrumentation>
<excludes>
<exclude>**/util/*.class</exclude>
</excludes>
</instrumentation>
<check>
<branchRate>90</branchRate>
<lineRate>90</lineRate>
Expand Down

0 comments on commit 2c5b089

Please sign in to comment.