Fixed unstable test. 59/6159/1
authorShigeru Yasuda <s-yasuda@da.jp.nec.com>
Mon, 14 Apr 2014 15:27:59 +0000 (00:27 +0900)
committerShigeru Yasuda <s-yasuda@da.jp.nec.com>
Mon, 14 Apr 2014 15:27:59 +0000 (00:27 +0900)
This patch fixes bug for unit test that the result was affected by
the order of test cases.

Change-Id: I2fa948882e7204e3cfd186c33490c13b8b49d9fc
Signed-off-by: Shigeru Yasuda <s-yasuda@da.jp.nec.com>
14 files changed:
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/ArpHandlerTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/EdgeUpdateStateTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/FlowModTaskTestBase.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/MacAddressTableTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/PacketContextTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/RemoteFlowRequestTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/TestUseVTNManagerBase.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/VNodeEventTestBase.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/VTNFlowDatabaseTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/VTNManagerImplClusterTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/VTNManagerImplTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/VTNManagerImplTestCommon.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/VTNManagerImplWithNodesTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/VTNThreadDataTest.java

index 9623758d23f2dd974573180b04d49c76af4f6e26..2cd8e6cb5eeb4d0e1459034b7a15381a3c027310 100644 (file)
@@ -17,8 +17,8 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import org.junit.BeforeClass;
 import org.junit.Test;
+
 import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Node;
@@ -68,10 +68,11 @@ public class ArpHandlerTest extends VTNManagerImplTestCommon {
      */
     private byte[] hostMac = new byte [] { 0x00, 0x00, 0x00, 0x11, 0x22, 0x33};
 
-
-    @BeforeClass
-    public static void beforeClass() {
-        stubMode = 2;
+    /**
+     * Construct a new instance.
+     */
+    public ArpHandlerTest() {
+        super(2);
     }
 
     /**
index 87d0c4e0b2fc251e54d2e9d93d906b4dd7792c7e..209c68a88cabde61992ccc588e1d643a065ccb3f 100644 (file)
@@ -16,7 +16,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 import org.opendaylight.controller.sal.core.Edge;
@@ -35,11 +34,10 @@ import org.opendaylight.controller.topologymanager.ITopologyManager;
  */
 public class EdgeUpdateStateTest extends TestUseVTNManagerBase {
     /**
-     * Called when the test class is loaded.
+     * Construct a new instance.
      */
-    @BeforeClass
-    public static void beforeClass() {
-        stubMode = 2;
+    public EdgeUpdateStateTest() {
+        super(2);
     }
 
     /**
index dc3bcc504ed426da6a39c4e9ac91b0142568a242..901d77ac33c581b6d172b8551d6026b57f2d4ce1 100644 (file)
@@ -1,11 +1,12 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this
  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.vtn.manager.internal;
 
 import java.util.Hashtable;
@@ -19,7 +20,7 @@ import java.util.TimerTask;
 import org.apache.felix.dm.impl.ComponentImpl;
 
 import org.junit.Before;
-import org.junit.BeforeClass;
+
 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
 import org.opendaylight.controller.forwardingrulesmanager.FlowConfig;
 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
@@ -357,10 +358,11 @@ public class FlowModTaskTestBase extends TestUseVTNManagerBase {
         }
     }
 
-
-    @BeforeClass
-    static public void beforeClass() {
-        stubMode = 2;
+    /**
+     * Construct a new instance.
+     */
+    public FlowModTaskTestBase() {
+        super(2);
     }
 
     @Before
index ed36d996e41793f0b1cc88816359c6407efcdeff..fb7070681ee92ebb2a786cd71cc669f376f870b9 100644 (file)
@@ -20,7 +20,7 @@ import java.util.TimerTask;
 import java.util.concurrent.ConcurrentMap;
 
 import org.apache.felix.dm.impl.ComponentImpl;
-import org.junit.BeforeClass;
+
 import org.junit.Test;
 
 import org.opendaylight.controller.sal.core.ConstructionException;
@@ -63,14 +63,12 @@ public class MacAddressTableTest extends TestUseVTNManagerBase {
     }
 
     /**
-     * setup a test environment for MacAddressTableTest.
+     * Construct a new instance.
      */
-    @BeforeClass
-    static public void beforeClass() {
-        stubMode = 2;
+    public MacAddressTableTest() {
+        super(2);
     }
 
-
     /**
      * Test case for {@link MacAddressTable#getTableKey(byte [])}.
      */
index 9c27cdeeae7971898160d49932a578db435739f2..5fa01c7a0b8042c0363f144e8301ab142b1ae1bf 100644 (file)
@@ -16,8 +16,8 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
 
-import org.junit.BeforeClass;
 import org.junit.Test;
+
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
@@ -56,10 +56,11 @@ import org.opendaylight.vtn.manager.internal.cluster.VlanMapPath;
  * JUnit test for {@link PacketContext}.
  */
 public class PacketContextTest extends TestUseVTNManagerBase {
-
-    @BeforeClass
-    public static void beforeClass() {
-        stubMode = 2;
+    /**
+     * Construct a new instance.
+     */
+    public PacketContextTest() {
+        super(2);
     }
 
     /**
index 020ae63093bfb983ceb3d2f84cb25f1570a5152c..29e0efdfe280609a10adb10ce2cbe6ba93396e58 100644 (file)
@@ -1,11 +1,12 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this
  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.vtn.manager.internal;
 
 import java.util.HashSet;
@@ -14,8 +15,8 @@ import java.util.Set;
 import java.util.Timer;
 import java.util.TimerTask;
 
-import org.junit.BeforeClass;
 import org.junit.Test;
+
 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
@@ -31,9 +32,11 @@ import org.opendaylight.vtn.manager.internal.cluster.VTNFlow;
  */
 public class RemoteFlowRequestTest extends TestUseVTNManagerBase {
 
-    @BeforeClass
-    static public void beforeClass() {
-        stubMode = 2;
+    /**
+     * Construct a new instance.
+     */
+    public RemoteFlowRequestTest() {
+        super(2);
     }
 
     /**
index 909fc47ec00d93b40c7025c88a5fc6e9a1d8d240..02b05a3400c4ce25fb492beb99ee0d100f481d72 100644 (file)
@@ -1,11 +1,12 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this
  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.vtn.manager.internal;
 
 import java.io.File;
@@ -54,11 +55,19 @@ import org.slf4j.LoggerFactory;
  * Common class for test of using VTNManager.
  */
 public class TestUseVTNManagerBase extends TestBase {
-    protected VTNManagerImpl vtnMgr = null;
+    protected VTNManagerImpl vtnMgr;
     protected GlobalResourceManager resMgr;
-    protected TestStub stubObj = null;
-    protected static int stubMode = 0;
-    protected static int clusterMode = 0;
+    protected TestStub stubObj;
+    protected int stubMode;
+
+    /**
+     * Construct a new instance.
+     *
+     * @param stub  An integer value to be passed to {@link TestStub}.
+     */
+    protected TestUseVTNManagerBase(int stub) {
+        stubMode = stub;
+    }
 
     @Before
     public void before() {
index ae4849bd43cb275f993051577012ee1b8db8447c..d66554a0424737969f3e5c23864c79961fba67b4 100644 (file)
@@ -1,11 +1,12 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this
  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.vtn.manager.internal;
 
 import java.util.ArrayList;
@@ -16,8 +17,9 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
 
 import org.apache.felix.dm.impl.ComponentImpl;
+
 import org.junit.Before;
-import org.junit.BeforeClass;
+
 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
 import org.opendaylight.vtn.manager.internal.cluster.ClusterEvent;
 import org.opendaylight.vtn.manager.internal.cluster.ClusterEventId;
@@ -28,9 +30,11 @@ import org.opendaylight.vtn.manager.internal.cluster.VNodeEvent;
  */
 public class VNodeEventTestBase extends TestUseVTNManagerBase {
 
-    @BeforeClass
-    public static void beforeClass() {
-        stubMode = 3;
+    /**
+     * Construct a new instance.
+     */
+    public VNodeEventTestBase() {
+        super(3);
     }
 
     @Before
@@ -99,4 +103,4 @@ public class VNodeEventTestBase extends TestUseVTNManagerBase {
         lock.lock();
         vtnMgr.unlock(lock, false);
     }
-}
\ No newline at end of file
+}
index 382448d913316ac414f3c56386b66878ac73f8be..73ada3ff2b55f8622ffde9163790675093d23fa7 100644 (file)
@@ -18,7 +18,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
 
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 import org.opendaylight.vtn.manager.VBridgeIfPath;
@@ -45,9 +44,11 @@ import org.opendaylight.controller.sal.utils.NodeCreator;
  */
 public class VTNFlowDatabaseTest extends TestUseVTNManagerBase {
 
-    @BeforeClass
-    public static void beforeClass() {
-        stubMode = 2;
+    /**
+     * Construct a new instance.
+     */
+    public VTNFlowDatabaseTest() {
+        super(2);
     }
 
     /**
index 3361c9b499955143f998455ebca34fd387d56a05..bb59522e59bdb3f3a9d1e82e5f6419ff442f5184 100644 (file)
@@ -24,8 +24,8 @@ import java.util.concurrent.ConcurrentMap;
 
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.impl.ComponentImpl;
+
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
@@ -103,10 +103,11 @@ import org.opendaylight.vtn.manager.internal.cluster.VlanMapEvent;
  * </p>
  */
 public class VTNManagerImplClusterTest extends VTNManagerImplTestCommon {
-
-    @BeforeClass
-    public static void beforeClass() {
-        stubMode = 3;
+    /**
+     * Construct a new instance.
+     */
+    public VTNManagerImplClusterTest() {
+        super(3);
     }
 
     @Before
index 547263ab9c044cce042cb734ce2f4d8af4b073b0..ebeebf5127c4dd64dcb1f5f182df6737a77a3a87 100644 (file)
@@ -30,7 +30,7 @@ import java.util.concurrent.ConcurrentMap;
 
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.impl.ComponentImpl;
-import org.junit.BeforeClass;
+
 import org.junit.Test;
 
 import org.opendaylight.vtn.manager.IVTNManagerAware;
@@ -108,10 +108,11 @@ import org.opendaylight.controller.topologymanager.ITopologyManager;
  * </p>
  */
 public class VTNManagerImplTest extends VTNManagerImplTestCommon {
-
-    @BeforeClass
-    public static void beforeClass() {
-        stubMode = 0;
+    /**
+     * Construct a new instance.
+     */
+    public VTNManagerImplTest() {
+        super(0);
     }
 
     /**
index 4a9e9857e14b842b057fa82bb39afe49fb9ee8a5..4c7db03bbddc266beea91684a3f95b60d706cf1a 100644 (file)
@@ -6,6 +6,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this
  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.vtn.manager.internal;
 
 import java.util.List;
@@ -54,6 +55,14 @@ import org.opendaylight.vtn.manager.internal.cluster.VlanMapPath;
  * Common class for tests of {@link VTNManagerImpl}.
  */
 public class VTNManagerImplTestCommon extends TestUseVTNManagerBase {
+    /**
+     * Construct a new instance.
+     *
+     * @param stub  An integer value to be passed to {@link TestStub}.
+     */
+    protected VTNManagerImplTestCommon(int stub) {
+        super(stub);
+    }
 
     /**
      * method for setup the environment.
index bf02a6bf3c115fd0c3139dc502c759a8aa3cd622..228c3088b97590f61fbfb013bd6ff26480b16726 100644 (file)
@@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentMap;
 
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.impl.ComponentImpl;
-import org.junit.BeforeClass;
+
 import org.junit.Test;
 
 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
@@ -92,10 +92,11 @@ import org.opendaylight.vtn.manager.internal.cluster.VlanMapImpl;
  * </p>
  */
 public class VTNManagerImplWithNodesTest extends VTNManagerImplTestCommon {
-
-    @BeforeClass
-    public static void beforeClass() {
-        stubMode = 2;
+    /**
+     * Construct a new instance.
+     */
+    public VTNManagerImplWithNodesTest() {
+        super(2);
     }
 
     /**
index b5614b573d9867d666275ab8239b718815ed2922..c9c22b852ce8a109c47c5426012761bae0812d61 100644 (file)
@@ -1,11 +1,12 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this
  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.vtn.manager.internal;
 
 import java.util.HashSet;
@@ -15,6 +16,7 @@ import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.junit.Test;
+
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.match.Match;
@@ -32,9 +34,15 @@ import org.opendaylight.vtn.manager.internal.cluster.FlowGroupId;
 import org.opendaylight.vtn.manager.internal.cluster.VTNFlow;
 
 /**
- * JUnit Test for {@link VTNThreadData}
+ * JUnit Test for {@link VTNThreadData}.
  */
 public class VTNThreadDataTest extends TestUseVTNManagerBase {
+    /**
+     * Construct a new instance.
+     */
+    public VTNThreadDataTest() {
+        super(2);
+    }
 
     /**
      * Test method for {@link VTNThreadData#create(Lock)}.