Merge pull request #410 from y-higuchi/no_commit_on_fail
Avoid NetworkGraph commit() if newSwitch() failed to create NetworkGraph vertex.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
index 03a5e8e..126efb3 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
@@ -72,7 +72,8 @@
log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
try {
- newSwitch(dpid);
+ ISwitchObject sw = newSwitch(dpid);
+ if ( sw == null ) throw new RuntimeException();
op.commit();
} catch (Exception e) {
e.printStackTrace();
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
index d2a6712..4956136 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
@@ -80,7 +80,6 @@
* Expect:
* Call SwitchStorageImpl.addSwitch func with proper properties.
*/
- @Ignore
@Test
public void testAddSwitch() {
String dpid = "00:00:00:00:00:00:0a:07";
@@ -144,7 +143,6 @@
* Expect:
* Write the status as info log.
*/
- //@Ignore
@Test
public void testAddSwitchAbnormal() {
String dpid = "00:00:00:00:00:00:0a:07";
@@ -152,6 +150,7 @@
//Expectation of mock operation.
expect(mockOpe.searchSwitch(dpid)).andReturn(null);
expect(mockOpe.newSwitch(dpid)).andReturn(null);
+ mockOpe.rollback();
mockOpe.close();
replay(mockOpe);
@@ -163,7 +162,7 @@
* Desc:
* Test method for addSwitch method.
* Condition:
- * Tthrow runtimeException.
+ * Throw runtimeException.
* Expect:
* The rollback method is called.
*/