X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsamples%2Fsimpleforwarding%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsamples%2Fsimpleforwarding%2Finternal%2FHostSwitchTest.java;fp=opendaylight%2Fsamples%2Fsimpleforwarding%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsamples%2Fsimpleforwarding%2Finternal%2FHostSwitchTest.java;h=0000000000000000000000000000000000000000;hp=6627029ef0ab658637c33d0d16ceb15d8cceb23d;hb=42c32160bfd41de57189bb246fec5ffb48ed8e9e;hpb=edf5bfcee83c750853253ccfd991ba7000f5f65b diff --git a/opendaylight/samples/simpleforwarding/src/test/java/org/opendaylight/controller/samples/simpleforwarding/internal/HostSwitchTest.java b/opendaylight/samples/simpleforwarding/src/test/java/org/opendaylight/controller/samples/simpleforwarding/internal/HostSwitchTest.java deleted file mode 100644 index 6627029ef0..0000000000 --- a/opendaylight/samples/simpleforwarding/src/test/java/org/opendaylight/controller/samples/simpleforwarding/internal/HostSwitchTest.java +++ /dev/null @@ -1,380 +0,0 @@ - -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. 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.controller.samples.simpleforwarding.internal; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.HashMap; -import org.junit.Test; -import org.junit.Assert; - -import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector; -import org.opendaylight.controller.sal.core.ConstructionException; -import org.opendaylight.controller.sal.utils.NodeCreator; -import org.opendaylight.controller.samples.simpleforwarding.HostNodePair; - - -public class HostSwitchTest { - @Test - public void TestEquality() { - HostNodeConnector h1 = null; - HostNodeConnector h2 = null; - - InetAddress ip1 = null; - try { - ip1 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - InetAddress ip2 = null; - try { - ip2 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - try { - h1 = new HostNodeConnector(ip1); - } catch (ConstructionException e) { - return; - } - try { - h2 = new HostNodeConnector(ip2); - } catch (ConstructionException e) { - return; - } - HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L)); - HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L)); - Assert.assertTrue(hsw1.equals(hsw2)); - } - - @Test - public void TestDiversityHost() { - HostNodeConnector h1 = null; - HostNodeConnector h2 = null; - InetAddress ip1 = null; - try { - ip1 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - InetAddress ip2 = null; - try { - ip2 = InetAddress.getByName("10.0.0.2"); - } catch (UnknownHostException e) { - return; - } - try { - h1 = new HostNodeConnector(ip1); - } catch (ConstructionException e) { - return; - } - try { - h2 = new HostNodeConnector(ip2); - } catch (ConstructionException e) { - return; - } - - HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L)); - HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L)); - Assert.assertTrue(!hsw1.equals(hsw2)); - } - - @Test - public void TestDiversitySwitch() { - HostNodeConnector h1 = null; - HostNodeConnector h2 = null; - InetAddress ip1 = null; - try { - ip1 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - InetAddress ip2 = null; - try { - ip2 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - try { - h1 = new HostNodeConnector(ip1); - } catch (ConstructionException e) { - return; - } - try { - h2 = new HostNodeConnector(ip2); - } catch (ConstructionException e) { - return; - } - - HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L)); - HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(2L)); - Assert.assertTrue(!hsw1.equals(hsw2)); - } - - @Test - public void TestDiversityAll() { - HostNodeConnector h1 = null; - HostNodeConnector h2 = null; - InetAddress ip1 = null; - try { - ip1 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - InetAddress ip2 = null; - try { - ip2 = InetAddress.getByName("10.0.0.2"); - } catch (UnknownHostException e) { - return; - } - try { - h1 = new HostNodeConnector(ip1); - } catch (ConstructionException e) { - return; - } - try { - h2 = new HostNodeConnector(ip2); - } catch (ConstructionException e) { - return; - } - - HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L)); - HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(2L)); - Assert.assertTrue(!hsw1.equals(hsw2)); - } - - @Test - public void TestEqualHashCode1() { - HostNodeConnector h1 = null; - HostNodeConnector h2 = null; - InetAddress ip1 = null; - try { - ip1 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - InetAddress ip2 = null; - try { - ip2 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - try { - h1 = new HostNodeConnector(ip1); - } catch (ConstructionException e) { - return; - } - try { - h2 = new HostNodeConnector(ip2); - } catch (ConstructionException e) { - return; - } - HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L)); - HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L)); - Assert.assertTrue(hsw1.hashCode() == hsw2.hashCode()); - } - - @Test - public void TestEqualHashCode2() { - HostNodeConnector h1 = null; - HostNodeConnector h2 = null; - InetAddress ip1 = null; - try { - ip1 = InetAddress.getByName("10.0.0.2"); - } catch (UnknownHostException e) { - return; - } - InetAddress ip2 = null; - try { - ip2 = InetAddress.getByName("10.0.0.2"); - } catch (UnknownHostException e) { - return; - } - try { - h1 = new HostNodeConnector(ip1); - } catch (ConstructionException e) { - return; - } - try { - h2 = new HostNodeConnector(ip2); - } catch (ConstructionException e) { - return; - } - - HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L)); - HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L)); - Assert.assertTrue(hsw1.hashCode() == hsw2.hashCode()); - } - - @Test - public void TestDiverseHashCodeHost() { - HostNodeConnector h1 = null; - HostNodeConnector h2 = null; - InetAddress ip1 = null; - try { - ip1 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - InetAddress ip2 = null; - try { - ip2 = InetAddress.getByName("10.0.0.2"); - } catch (UnknownHostException e) { - return; - } - try { - h1 = new HostNodeConnector(ip1); - } catch (ConstructionException e) { - return; - } - try { - h2 = new HostNodeConnector(ip2); - } catch (ConstructionException e) { - return; - } - HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L)); - HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L)); - Assert.assertTrue(hsw1.hashCode() != hsw2.hashCode()); - } - - @Test - public void TestDiverseHashCodeSwitch() { - HostNodeConnector h1 = null; - HostNodeConnector h2 = null; - InetAddress ip1 = null; - try { - ip1 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - InetAddress ip2 = null; - try { - ip2 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - try { - h1 = new HostNodeConnector(ip1); - } catch (ConstructionException e) { - return; - } - try { - h2 = new HostNodeConnector(ip2); - } catch (ConstructionException e) { - return; - } - - HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L)); - HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(2L)); - Assert.assertTrue(hsw1.hashCode() != hsw2.hashCode()); - } - - @Test - public void TestDiverseHashCodeAll() { - HostNodeConnector h1 = null; - HostNodeConnector h2 = null; - InetAddress ip1 = null; - try { - ip1 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - InetAddress ip2 = null; - try { - ip2 = InetAddress.getByName("10.0.0.3"); - } catch (UnknownHostException e) { - return; - } - try { - h1 = new HostNodeConnector(ip1); - } catch (ConstructionException e) { - return; - } - try { - h2 = new HostNodeConnector(ip2); - } catch (ConstructionException e) { - return; - } - - HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L)); - HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(2L)); - Assert.assertTrue(hsw1.hashCode() != hsw2.hashCode()); - } - - @Test - public void TestUsageAsKey() { - HostNodeConnector h1 = null; - HostNodeConnector h2 = null; - InetAddress ip1 = null; - try { - ip1 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - InetAddress ip2 = null; - try { - ip2 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - try { - h1 = new HostNodeConnector(ip1); - } catch (ConstructionException e) { - return; - } - try { - h2 = new HostNodeConnector(ip2); - } catch (ConstructionException e) { - return; - } - - HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L)); - HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L)); - HashMap hm = new HashMap(); - hm.put(hsw1, new Long(10)); - Assert.assertTrue(hm.get(hsw2) != null); - Assert.assertTrue(hm.get(hsw2).equals(new Long(10))); - } - - @Test - public void TestUsageAsKeyChangingField() { - HostNodeConnector h1 = null; - HostNodeConnector h2 = null; - InetAddress ip1 = null; - try { - ip1 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - InetAddress ip2 = null; - try { - ip2 = InetAddress.getByName("10.0.0.1"); - } catch (UnknownHostException e) { - return; - } - try { - h1 = new HostNodeConnector(ip1); - } catch (ConstructionException e) { - return; - } - try { - h2 = new HostNodeConnector(ip2); - } catch (ConstructionException e) { - return; - } - HostNodePair hsw1 = new HostNodePair(h1, null); - HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L)); - hsw1.setNode(NodeCreator.createOFNode(1L)); - HashMap hm = new HashMap(); - hm.put(hsw1, new Long(10)); - Assert.assertTrue(hm.get(hsw2) != null); - Assert.assertTrue(hm.get(hsw2).equals(new Long(10))); - } -} \ No newline at end of file