Guest User

Untitled

a guest
Jan 15th, 2018
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 47.10 KB | None | 0 0
  1. package dons.chord.test;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import java.util.HashMap;
  6. import java.util.Iterator;
  7. import java.util.UUID;
  8. import java.util.Vector;
  9.  
  10. import org.junit.Before;
  11. import org.junit.Test;
  12.  
  13. import sun.security.x509.OtherName;
  14. import tigase.server.Packet;
  15. import tigase.util.TigaseStringprepException;
  16. import tigase.xml.Element;
  17. import tigase.xmpp.JID;
  18. import tigase.xmpp.StanzaType;
  19.  
  20. import dons.ParameterObject;
  21. import dons.chord.ChordKey;
  22. import dons.chord.ChordNeighborNode;
  23. import dons.chord.ChordNode;
  24. import dons.chord.FingerTable;
  25. import dons.chord.PendingFSOperation;
  26.  
  27. public class ChordNodeTest {
  28.  
  29.     ChordNode nodeUnderTest;
  30.     ChordKey nodeKey;
  31.     String hostname;
  32.    
  33.     @Before
  34.     public void createChordNode(){
  35.         hostname = "mh.local";
  36.         this.nodeUnderTest = new ChordNode(hostname, null);
  37.         this.nodeUnderTest.test = true;
  38.         this.nodeKey = new ChordKey(hostname);
  39.     }
  40.    
  41.    
  42.     @Test
  43.     public void testCreateChordNode() {
  44.         assertEquals(hostname, nodeUnderTest.getNodeId());
  45.         assertEquals(nodeKey.toString(),nodeUnderTest.getNodeKey().toString());
  46.         //assertEquals(nodeUnderTest.getPredecessor(), null);
  47.         assertEquals(nodeUnderTest.getSuccessor().getNodeId(), hostname);
  48.         assertEquals("dhtsearch@mh.local", nodeUnderTest.getSelf().getJID().toString());
  49.         //System.out.println(node.printFingerTable());
  50.     }
  51.    
  52.     // createFindSuccessorGet
  53.     @Test
  54.     public void testCreateFindSuccessorGet0(){
  55.         String ID = UUID.randomUUID().toString();
  56.         nodeUnderTest.createFindSuccessorGet(nodeUnderTest.getSelf(), nodeKey, ID, "0");
  57.         Packet actual = nodeUnderTest.testPackets.get(0);
  58.         assertEquals(StanzaType.get.toString(), actual.getType().toString());
  59.         assertEquals(nodeUnderTest.getSelf().getJID().toString() ,actual.getFrom().toString());
  60.         assertEquals(nodeUnderTest.getSelf().getJID().toString(), actual.getTo().toString());
  61.         assertEquals(ID, actual.getAttribute("id"));
  62.         assertEquals(nodeKey.toString(), actual.getElemCData("iq/query/key"));
  63.         assertEquals("0", actual.getAttribute("seq"));
  64.     }
  65.    
  66.  
  67.     @Test
  68.     public void testCreateFindSuccessorGet1(){
  69.         ChordNode otherNode = new ChordNode("test.de", null);
  70.         String ID = UUID.randomUUID().toString();
  71.         nodeUnderTest.createFindSuccessorGet(otherNode.getSelf(), nodeKey, ID, "0");
  72.         Packet actual = nodeUnderTest.testPackets.get(0);
  73.         assertEquals(StanzaType.get.toString(), actual.getType().toString());
  74.         assertEquals(nodeUnderTest.getSelf().getJID().toString() ,actual.getFrom().toString());
  75.         assertEquals(otherNode.getSelf().getJID().toString(), actual.getTo().toString());
  76.         assertEquals(ID, actual.getAttribute("id"));
  77.         assertEquals(nodeKey.toString(), actual.getElemCData("iq/query/key"));
  78.         assertEquals("0", actual.getAttribute("seq"));
  79.     }
  80.    
  81.     @Test
  82.     /**
  83.      * generated Message:
  84.      * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@test.de" type="get">
  85.      *  <query xmlns="dhtsearch.findsuccessor">
  86.      *   <key>.....</key>
  87.      *  </query>
  88.      * </iq>
  89.      *
  90.      * answered with:
  91.      * <iq id="xyz" seq="0" from="dhtsearch@test.de" to="dhtsearch@mh.local" type="result">
  92.      *  <query xmlns="dhtsearch.findsuccessor">
  93.      *   <host>test.de</host>
  94.      *  </query>
  95.      * </iq>
  96.      *
  97.      * precondition after triggered join method:
  98.      * - size of openOperations: 1
  99.      * - generated Message is in testPacket
  100.      * - size of getPendingFSOperations: 0
  101.      *
  102.      * postcondition:
  103.      * - size if openOperations: 0
  104.      * - size of getPendingFSOperation: 0
  105.      * - successor = test.de
  106.      *
  107.      */
  108.     public void testJoin0() throws TigaseStringprepException{
  109.         ChordNode otherNode = new ChordNode("test.de", null);
  110.         this.nodeUnderTest.join(new ChordNeighborNode(otherNode.getNodeId(), otherNode.getNodeKey()));
  111.         assertEquals(1,this.nodeUnderTest.getOpenOperations().size());
  112.         assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
  113.        
  114.         // test outgoing Packet
  115.         Packet actual = nodeUnderTest.testPackets.get(0);
  116.         assertEquals(StanzaType.get.toString(), actual.getType().toString());
  117.         assertEquals("0", actual.getAttribute("seq"));
  118.         assertEquals(otherNode.getSelf().getJID().toString(), actual.getTo().toString());
  119.         assertEquals(nodeUnderTest.getSelf().getJID().toString(), actual.getFrom().toString());
  120.         assertEquals(actual.getAttribute("iq/query", "xmlns"), "dhtsearch:findsuccessor");
  121.         assertEquals(actual.getElemCData("iq/query/key"), this.nodeUnderTest.getNodeKey().toString());
  122.        
  123.         // generate incomming packet
  124.         Element host = new Element("host", otherNode.getNodeId());
  125.         JID from = otherNode.getSelf().getJID();
  126.         JID to = this.nodeUnderTest.getSelf().getJID();
  127.         Element hostElement = new Element("host", otherNode.getNodeId());
  128.         String[] queryAttrValue = {"dhtsearch:findsuccessor"};
  129.         String[] queryAttrKey = {"xmlns"};
  130.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  131.         queryElement.addChild(hostElement);
  132.         int seq = 0;
  133.         if(seq != 0) // catch the basic case: self is result
  134.                 seq--;
  135.         String strSeq = String.valueOf(seq);
  136.         String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
  137.         String[] iqAttrValue = {from.toString(), to.toString(), actual.getAttribute("id"), strSeq, "result"};
  138.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  139.         iqElement.addChild(queryElement);
  140.         Packet fsResult = null;
  141.         fsResult = Packet.packetInstance(iqElement);
  142.  
  143.         // test the
  144.         this.nodeUnderTest.update(null, fsResult);
  145.         assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
  146.         assertEquals(otherNode.getNodeId(), this.nodeUnderTest.getSuccessor().getNodeId());
  147.         assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
  148.     }
  149.    
  150.     @Test
  151.     /**
  152.      * generated Message:
  153.      * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="get">
  154.      *  <query xmlns="dhtsearch.findsuccessor">
  155.      *   <key>.....</key>
  156.      *  </query>
  157.      * </iq>
  158.      *
  159.      * answered with:
  160.      * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="result">
  161.      *  <query xmlns="dhtsearch.findsuccessor">
  162.      *   <host>mh.local</host>
  163.      *  </query>
  164.      * </iq>
  165.      *
  166.      * preconditions
  167.      * - size of openOperations: 0
  168.      * - size of getPendingFSOperations: 0
  169.      *
  170.      * postcondition:s
  171.      * - size if openOperations: 0
  172.      * - size of getPendingFSOperation: 0
  173.      * - resultMessage is in testpacket
  174.      *
  175.      */
  176.     public void testReceiveGetMessage0() throws TigaseStringprepException{
  177.         assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
  178.         assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
  179.        
  180.         // generate incomming packet
  181.         String ID = UUID.randomUUID().toString();
  182.         Element key = new Element("key", this.nodeUnderTest.getNodeKey().toString());
  183.         JID from = this.nodeUnderTest.getSelf().getJID();
  184.         JID to = this.nodeUnderTest.getSelf().getJID();
  185.         String[] queryAttrValue = {"dhtsearch:findsuccessor"};
  186.         String[] queryAttrKey = {"xmlns"};
  187.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  188.         queryElement.addChild(key);
  189.         int seq = 0;
  190.         String strSeq = String.valueOf(seq);
  191.         String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
  192.         String[] iqAttrValue = {from.toString(), to.toString(), ID, strSeq, "get"};
  193.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  194.         iqElement.addChild(queryElement);
  195.         Packet fsResult = null;
  196.         fsResult = Packet.packetInstance(iqElement);
  197.         this.nodeUnderTest.update(null, fsResult);
  198.        
  199.         // test resultMessage
  200.         Packet actual = this.nodeUnderTest.testPackets.get(0);
  201.         assertEquals(actual.getAttribute("id"), ID);
  202.         assertEquals(actual.getAttribute("seq"), "0");
  203.         assertEquals(actual.getAttribute("type"), StanzaType.result.toString());
  204.         assertEquals(actual.getElemCData("iq/query/host"), this.nodeUnderTest.getNodeId());
  205.         assertEquals(actual.getAttribute("iq/query", "xmlns"), "dhtsearch:findsuccessor");
  206.         assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
  207.         assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
  208.     }
  209.    
  210.     @Test
  211.     /**
  212.      * ---->[noderUnderTest]--|key|-->[othernode]---->
  213.      * key is between nodeUnderTest and its successor and nodeUnderTest starts the search
  214.      *
  215.      * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
  216.      * key otherNode (test.org): 247.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21
  217.      *
  218.      * generated Message:
  219.      * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="get">
  220.      *  <query xmlns="dhtsearch.findsuccessor">
  221.      *   <key>200.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132</key>
  222.      *  </query>
  223.      * </iq>
  224.      *
  225.      * answered with:
  226.      * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="result">
  227.      *  <query xmlns="dhtsearch.findsuccessor">
  228.      *   <host>test.org</host>
  229.      *  </query>
  230.      * </iq>
  231.      *
  232.      * preconditions
  233.      * - size of openOperations: 0
  234.      * - size of getPendingFSOperations: 0
  235.      *
  236.      * postcondition:s
  237.      * - size if openOperations: 0
  238.      * - size of getPendingFSOperation: 0
  239.      * - resultMessage is in testpacket
  240.      *
  241.      */
  242.     public void testReceiveGetMessage1() throws TigaseStringprepException{
  243.         ChordNeighborNode otherNode = new ChordNeighborNode("test.org", new ChordKey("test.org"));
  244.         this.nodeUnderTest.setSuccessor(otherNode);
  245.        
  246.         // generate incomming packet
  247.         String ID = UUID.randomUUID().toString();
  248.         Element key = new Element("key", "200.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132");
  249.         JID from = this.nodeUnderTest.getSelf().getJID();
  250.         JID to = this.nodeUnderTest.getSelf().getJID();
  251.         String[] queryAttrValue = {"dhtsearch:findsuccessor"};
  252.         String[] queryAttrKey = {"xmlns"};
  253.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  254.         queryElement.addChild(key);
  255.         int seq = 0;
  256.         String strSeq = String.valueOf(seq);
  257.         String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
  258.         String[] iqAttrValue = {from.toString(), to.toString(), ID, strSeq, "get"};
  259.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  260.         iqElement.addChild(queryElement);
  261.         Packet fsResult = null;
  262.         fsResult = Packet.packetInstance(iqElement);
  263.         this.nodeUnderTest.update(null, fsResult);
  264.        
  265.         // rest result message // TODO flip arguments
  266.         Packet actual = this.nodeUnderTest.testPackets.get(0);
  267.         assertEquals(actual.getAttribute("id"), ID);
  268.         assertEquals(actual.getAttribute("seq"), "0");
  269.         assertEquals(actual.getAttribute("type"), StanzaType.result.toString());
  270.         assertEquals(actual.getElemCData("iq/query/host"), otherNode.getNodeId());
  271.         assertEquals(actual.getAttribute("iq/query", "xmlns"), "dhtsearch:findsuccessor");
  272.         assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
  273.         assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
  274.     }
  275.  
  276.    
  277.     @Test
  278.     /**
  279.      * ---->[noderUnderTest]--|key|-->[othernode]---->
  280.      * key is between nodeUnderTest and its successor and a node before noderUnderTest starts the search
  281.      *
  282.      * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
  283.      * key otherNode (test.org): 247.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21
  284.      *
  285.      * generated Message:
  286.      * <iq id="xyz" seq="5" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="get">
  287.      *  <query xmlns="dhtsearch.findsuccessor">
  288.      *   <key>200.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132</key>
  289.      *  </query>
  290.      * </iq>
  291.      *
  292.      * answered with:
  293.      * <iq id="xyz" seq="4" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="result">
  294.      *  <query xmlns="dhtsearch.findsuccessor">
  295.      *   <host>test.org</host>
  296.      *  </query>
  297.      * </iq>
  298.      *
  299.      * preconditions
  300.      * - size of openOperations: 0
  301.      * - size of getPendingFSOperations: 0
  302.      *
  303.      * postcondition:s
  304.      * - size if openOperations: 0
  305.      * - size of getPendingFSOperation: 0
  306.      * - resultMessage is in testpacket
  307.      *
  308.      */
  309.     public void testReceiveGetMessage2() throws TigaseStringprepException{
  310.        
  311.         ChordNeighborNode otherNode = new ChordNeighborNode("test.org", new ChordKey("test.org"));
  312.         this.nodeUnderTest.setSuccessor(otherNode);
  313.        
  314.         // generate incomming packet
  315.         String ID = UUID.randomUUID().toString();
  316.         Element key = new Element("key", "200.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132");
  317.         JID from = JID.jidInstance("dhtseatch@testserver3.com");
  318.         JID to = this.nodeUnderTest.getSelf().getJID();
  319.         String[] queryAttrValue = {"dhtsearch:findsuccessor"};
  320.         String[] queryAttrKey = {"xmlns"};
  321.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  322.         queryElement.addChild(key);
  323.         int seq = 5;
  324.         String strSeq = String.valueOf(seq);
  325.         String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
  326.         String[] iqAttrValue = {from.toString(), to.toString(), ID, strSeq, "get"};
  327.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  328.         iqElement.addChild(queryElement);
  329.         Packet fsResult = null;
  330.         fsResult = Packet.packetInstance(iqElement);
  331.         this.nodeUnderTest.update(null, fsResult);
  332.        
  333.         // rest result message
  334.         Packet actual = this.nodeUnderTest.testPackets.get(0);
  335.         assertEquals(ID, actual.getAttribute("id"));
  336.         assertEquals("4", actual.getAttribute("seq"));
  337.         assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
  338.         assertEquals(otherNode.getNodeId(), actual.getElemCData("iq/query/host"));
  339.         assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
  340.         assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
  341.     }
  342.    
  343.    
  344.     @Test
  345.     /**
  346.      * ---->[otherNode1]---->[noderUnderTest]---->[otherNode2]--|key|-->
  347.      * key is after othernode 2 and othernode1 sends a get findsuccessor so nodeUnderTest has to forward
  348.      * this message
  349.      * key otherNode1 (test.net):9.76.81.242.102.55.25.149.96.141.200.212.100.112.162.48.242.198.165.66
  350.      * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
  351.      * key otherNode (test.org): 247.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21
  352.      *
  353.      * generated Message:
  354.      * <iq id="xyz" seq="5" from="test.net" to="mh.local" type="get">
  355.      *  <query xmlns="dhtsearch.findsuccessor">
  356.      *   <key>248.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132</key>
  357.      *  </query>
  358.      * </iq>
  359.      *
  360.      * answered with:
  361.      * <iq id="xyz" seq="6" from="mh.local" to="test.org" type="get">
  362.      *  <query xmlns="dhtsearch.findsuccessor">
  363.      *   <key>248.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132</key>
  364.      *  </query>
  365.      * </iq>
  366.      *
  367.      * preconditions
  368.      * - size of openOperations: 0
  369.      * - size of getPendingFSOperations: 0
  370.      *
  371.      * postcondition:s
  372.      * - size if openOperations: 0
  373.      * - size of getPendingFSOperation: 1
  374.      * - resultMessage is in testpacket
  375.      *
  376.      */
  377.     public void testReceiveGetMessage3() throws TigaseStringprepException{
  378.         ChordNeighborNode otherNode1 = new ChordNeighborNode("test.net", new ChordKey("test.net"));
  379.         this.nodeUnderTest.setPredecessor(otherNode1);
  380.         ChordNeighborNode otherNode2 = new ChordNeighborNode("test.org", new ChordKey("test.org"));
  381.         this.nodeUnderTest.setSuccessor(otherNode2);
  382.        
  383.         // generate incomming packet
  384.         String ID = UUID.randomUUID().toString();
  385.         Element key = new Element("key", "248.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132");
  386.         JID from = JID.jidInstance("dhtsearch@test.net");
  387.         JID to = this.nodeUnderTest.getSelf().getJID();
  388.         String[] queryAttrValue = {"dhtsearch:findsuccessor"};
  389.         String[] queryAttrKey = {"xmlns"};
  390.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  391.         queryElement.addChild(key);
  392.         int seq = 5;
  393.         String strSeq = String.valueOf(seq);
  394.         String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
  395.         String[] iqAttrValue = {from.toString(), to.toString(), ID, strSeq, "get"};
  396.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  397.         iqElement.addChild(queryElement);
  398.         Packet fsResult = null;
  399.         fsResult = Packet.packetInstance(iqElement);
  400.         this.nodeUnderTest.update(null, fsResult);
  401.        
  402.         // rest result message
  403.         Packet actual = this.nodeUnderTest.testPackets.get(0);
  404.         assertEquals(ID, actual.getAttribute("id"));
  405.         assertEquals("6", actual.getAttribute("seq"));
  406.         assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
  407.         assertEquals("248.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132", actual.getElemCData("iq/query/key"));
  408.         assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
  409.         assertEquals(1, this.nodeUnderTest.getPendingFSOperations().size());
  410.     }
  411.    
  412.     @Test
  413.     /**
  414.      * --->[otherNode1]---->[noderUnderTest]---->[otherNode2]--|key|-->
  415.      * key is after othernode 2 and a node before nodeUnderTest asks for a key so nodeUnder test has to
  416.      * forward the result
  417.      * key otherNode1 (test.net):9.76.81.242.102.55.25.149.96.141.200.212.100.112.162.48.242.198.165.66
  418.      * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
  419.      * key otherNode2 (test.org): 247.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21
  420.      *
  421.      * generated Message:
  422.      *
  423.      * <id id="xyz" seq="5" from="test.net" to"mh.local" type="get">
  424.      *  <query xmlns="dhtsearch.findsuccessor">
  425.      *   <key>257.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21</key>
  426.      *  </query>
  427.      * </id>
  428.      *
  429.      * Message send to nodeUnderTest:
  430.      * <iq id="xyz" seq="5" from="test.org" to="mh.local" type="result">
  431.      *  <query xmlns="dhtsearch.findsuccessor">
  432.      *   <host>test.ru</host>
  433.      *  </query>
  434.      * </iq>
  435.      *
  436.      * answered with:
  437.      * <iq id="xyz" seq="4" from="mh.local" to="test.net" type="result">
  438.      *  <query xmlns="dhtsearch.findsuccessor">
  439.      *   <host>test.ru</host>
  440.      *  </query>
  441.      * </iq>
  442.      *
  443.      * preconditions
  444.      * - size of openOperations: 0
  445.      * - size of getPendingFSOperations: 1
  446.      *
  447.      * postcondition:s
  448.      * - size if openOperations: 0
  449.      * - size of getPendingFSOperation: 0
  450.      * - resultMessage is in testpacket
  451.      *
  452.      */
  453.     public void testReceiveResultMessage0() throws TigaseStringprepException{
  454.         ChordNeighborNode otherNode1 = new ChordNeighborNode("test.net", new ChordKey("test.net"));
  455.         this.nodeUnderTest.setPredecessor(otherNode1);
  456.         ChordNeighborNode otherNode2 = new ChordNeighborNode("test.org", new ChordKey("test.org"));
  457.         this.nodeUnderTest.setSuccessor(otherNode2);
  458.        
  459.         // generate packet for fsPending-Object
  460.         String ID = UUID.randomUUID().toString();
  461.         Element key = new Element("key", "257.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21");
  462.         JID from = otherNode1.getJID();
  463.         JID to = this.nodeUnderTest.getSelf().getJID();
  464.         String[] queryAttrValue = {"dhtsearch:findsuccessor"};
  465.         String[] queryAttrKey = {"xmlns"};
  466.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  467.         queryElement.addChild(key);
  468.         int seq = 5;
  469.         String strSeq = String.valueOf(seq);
  470.         String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
  471.         String[] iqAttrValue = {from.toString(), to.toString(), ID, strSeq, "get"};
  472.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  473.         iqElement.addChild(queryElement);
  474.         Packet fsResult = null;
  475.         fsResult = Packet.packetInstance(iqElement);
  476.         // add the package as an pending operation
  477.         PendingFSOperation pendingFs = new PendingFSOperation(fsResult);
  478.         this.nodeUnderTest.getPendingFSOperations().put(ID, pendingFs);
  479.        
  480.         //test preconditions
  481.         assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
  482.         assertEquals(1, this.nodeUnderTest.getPendingFSOperations().size());
  483.        
  484.         // generate incomming packet
  485.         Element key_1 = new Element("host", "test.ru");
  486.         JID from_1 = otherNode2.getJID();
  487.         JID to_1 = this.nodeUnderTest.getSelf().getJID();
  488.         String[] queryAttrValue_1 = {"dhtsearch:findsuccessor"};
  489.         String[] queryAttrKey_1 = {"xmlns"};
  490.         Element queryElement_1 = new Element("query", queryAttrKey_1, queryAttrValue_1);
  491.         queryElement_1.addChild(key_1);
  492.         int seq_1 = 5;
  493.         String strSeq_1 = String.valueOf(seq_1);
  494.         String[] iqAttrKey_1 = {"from", "to", "id", "seq", "type"};
  495.         String[] iqAttrValue_1 = {from_1.toString(), to_1.toString(), ID, strSeq_1, "result"};
  496.         Element iqElement_1 = new Element("iq", iqAttrKey_1, iqAttrValue_1);
  497.         iqElement_1.addChild(queryElement_1);
  498.         Packet fsResult_1 = null;
  499.         fsResult_1 = Packet.packetInstance(iqElement_1);
  500.         this.nodeUnderTest.update(null, fsResult_1);
  501.  
  502.         // test result message
  503.         Packet actual = this.nodeUnderTest.testPackets.get(0);
  504.         assertEquals(ID, actual.getAttribute("id"));
  505.         assertEquals("4", actual.getAttribute("seq"));
  506.         assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
  507.         assertEquals("test.ru", actual.getElemCData("iq/query/host"));
  508.         assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
  509.         assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
  510.     }
  511.    
  512.     @Test
  513.     /**
  514.      * test the message format for a stabilize result Message (getPredecessor produces this message)
  515.      *
  516.      * incoming Message:
  517.      * <iq from="successor.nodeUnderTest" to="nodeUnderTest" id="xyz" type="get">
  518.      *  <query xmlns"dhtSearch:getPredecessor />
  519.      *  </query>
  520.      * </iq>
  521.      *
  522.      *
  523.      * <iq from="nodeUnderTest" to="successor.nodeUnderTest" id="xyz" type="result">
  524.      *  <query xmlns"dhtSearch:getPredecessor" />
  525.      *   <host>nodeUnderTest.predecessor</host>
  526.      *  </query>
  527.      * </iq>
  528.      */
  529.     public void testGetPredecessorMessage() throws TigaseStringprepException{
  530.         // set preconditions
  531.         ChordNeighborNode otherNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
  532.         this.nodeUnderTest.setPredecessor(otherNode);
  533.        
  534.         // construct incomming message
  535.         JID from = otherNode.getJID();
  536.         JID to = this.nodeUnderTest.getSelf().getJID();
  537.         String[] queryAttrValue = {"dhtsearch:getpredecessor"};
  538.         String[] queryAttrKey = {"xmlns"};
  539.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  540.         String[] iqAttrKey = {"from", "to", "id", "type"};
  541.         String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "get"};
  542.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  543.         iqElement.addChild(queryElement);
  544.         Packet fsGet = Packet.packetInstance(iqElement);
  545.        
  546.         this.nodeUnderTest.getPredecessor(fsGet);
  547.         Packet actual = this.nodeUnderTest.testPackets.get(0);
  548.         assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
  549.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
  550.         assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
  551.         assertEquals(otherNode.getNodeId(), actual.getElemCData("iq/query/host"));
  552.     }
  553.    
  554.     @Test
  555.     /**
  556.      * test the message format for a stabilize get Message
  557.      * <iq from="nodeUnderTest" to="successor.nodeUnderTest" id="xyz" type="get">
  558.      *  <query xmlns="dhtsearch:getPredecessor />
  559.      * </iq>
  560.      */
  561.     public void testStabilize0(){
  562.         // set preconditions
  563.         ChordNeighborNode otherNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
  564.         this.nodeUnderTest.setSuccessor(otherNode);
  565.        
  566.         // invoke method
  567.         this.nodeUnderTest.stabilize(null);
  568.        
  569.         Packet actual = this.nodeUnderTest.testPackets.get(0);
  570.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
  571.         assertEquals(this.nodeUnderTest.getSuccessor().getJID().toString(), actual.getAttribute("to"));
  572.         assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
  573.         assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
  574.     }
  575.    
  576.     @Test
  577.     /**
  578.      * test the message format for a stabilize result Message
  579.      * <iq from="successor.nodeUnderTest" id="xyz" type="result">
  580.      *  <query xmlns"dhtSearch:getPredecessor />
  581.      *   <host>successor.predecessor</host>
  582.      *  </query>
  583.      * </iq>
  584.      */
  585.     public void testStabilize1() throws TigaseStringprepException{
  586.         // set preconditions
  587.         ChordNeighborNode otherNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
  588.         this.nodeUnderTest.setPredecessor(otherNode);
  589.        
  590.         // generate test get message
  591.         JID from = otherNode.getJID();
  592.         JID to = this.nodeUnderTest.getSelf().getJID();
  593.         String[] queryAttrValue = {"dhtsearch:getpredecessor"};
  594.         String[] queryAttrKey = {"xmlns"};
  595.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  596.         String[] iqAttrKey = {"from", "to", "id", "type"};
  597.         String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "get"};
  598.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  599.         iqElement.addChild(queryElement);
  600.         Packet fsGet = Packet.packetInstance(iqElement);
  601.         this.nodeUnderTest.update(null, fsGet);
  602.        
  603.         // check result
  604.         Packet actual = this.nodeUnderTest.testPackets.get(0);
  605.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
  606.         assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
  607.         assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
  608.         assertEquals("test.de", actual.getElemCData("iq/query/host"));
  609.     }
  610.    
  611.     @Test
  612.     /**
  613.      *            __________->successor->__________
  614.      *           /                                 \
  615.      * --->[nodeUnderTest]                      [otherNode]--->
  616.      *          \__________<-predecessor<-__________/
  617.      *
  618.      * nodeUnderTest hast to send this message:
  619.      *
  620.      * <iq from="nodeUnderTest" to="otherNode" type="get" id="">
  621.      *  <query xmlns="dhtsearch:getpredecessor" />
  622.      * </iq>
  623.      *
  624.      * noderUnderTest then receives this message:
  625.      *  
  626.      * <iq from="otherNode" to="noderUnderTest" type="result" id"">
  627.      *  <query xmlns="dhtsearch.getpredecessor>
  628.      *   </host>nodeUnderTest.getNodeID</host>
  629.      *  </query>
  630.      * </iq>
  631.      *
  632.      */
  633.     public void testStabilize2() throws TigaseStringprepException{
  634.         // set preconditions
  635.         ChordNeighborNode otherNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
  636.         this.nodeUnderTest.setSuccessor(otherNode);
  637.        
  638.         // invoke stabilize
  639.         this.nodeUnderTest.stabilize(null);
  640.        
  641.         // test the resulting package
  642.         Packet actual = this.nodeUnderTest.testPackets.get(0);
  643.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
  644.         assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
  645.         assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
  646.         assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
  647.        
  648.         // construct answer from otherNode
  649.         JID from = otherNode.getJID();
  650.         JID to = this.nodeUnderTest.getSelf().getJID();
  651.         String[] queryAttrValue = {"dhtsearch:getpredecessor"};
  652.         String[] queryAttrKey = {"xmlns"};
  653.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  654.         String[] iqAttrKey = {"from", "to", "id", "type"};
  655.         String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "result"};
  656.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  657.         iqElement.addChild(queryElement);
  658.         Element hostElement = new Element("host", "mh.local");
  659.         queryElement.addChild(hostElement);
  660.         Packet fsGet = Packet.packetInstance(iqElement);
  661.  
  662.         this.nodeUnderTest.update(null, fsGet);
  663.        
  664.         assertEquals(otherNode.getJID(), this.nodeUnderTest.getSuccessor().getJID());
  665.     }
  666.    
  667.     @Test
  668.     /**
  669.      *            __________->successor->__________
  670.      *           /                                 \
  671.      * --->[nodeUnderTest]                      [otherNode]--->
  672.      *                                  X__________/   
  673.      *
  674.      * nodeUnderTest has to send this message:
  675.      *
  676.      * <iq from="nodeUnderTest" to="otherNode" type="get" id="">
  677.      *  <query xmlns="dhtsearch:getpredecessor" />
  678.      * </iq>
  679.      *
  680.      *
  681.      * noderUnderTest then receives this message:
  682.      *  
  683.      * <iq from="otherNode" to="noderUnderTest" type="get" id"">
  684.      *  <query xmlns="dhtsearch.getpredecessor>
  685.      *   </host>hohost</host>
  686.      *  </query>
  687.      * </iq>
  688.      *
  689.      */
  690.     public void testStabilize3() throws TigaseStringprepException{
  691.         // set preconditions
  692.         ChordNeighborNode otherNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
  693.         this.nodeUnderTest.setSuccessor(otherNode);
  694.        
  695.         // invoke stabilize
  696.         this.nodeUnderTest.stabilize(null);
  697.        
  698.         // test the resulting package
  699.         Packet actual = this.nodeUnderTest.testPackets.lastElement();
  700.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
  701.         assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
  702.         assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
  703.         assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
  704.        
  705.         // construct the answert from otherNode
  706.         JID from = otherNode.getJID();
  707.         JID to = this.nodeUnderTest.getSelf().getJID();
  708.         String[] queryAttrValue = {"dhtsearch:getpredecessor"};
  709.         String[] queryAttrKey = {"xmlns"};
  710.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  711.         String[] iqAttrKey = {"from", "to", "id", "type"};
  712.         String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "result"};
  713.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  714.         iqElement.addChild(queryElement);
  715.         Element hostElement = new Element("host", "nohost");
  716.         queryElement.addChild(hostElement);
  717.         Packet fsGet = Packet.packetInstance(iqElement);
  718.         this.nodeUnderTest.update(null, fsGet);
  719.         // test
  720.         assertEquals(this.nodeUnderTest.getSuccessor().getNodeId(), otherNode.getNodeId());
  721.        
  722.         // has to result in a notify predecessor Message
  723.         actual = this.nodeUnderTest.testPackets.lastElement();
  724.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
  725.         assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
  726.         assertEquals(StanzaType.set.toString(), actual.getAttribute("type"));
  727.         assertEquals("dhtsearch:notifypredecessor", actual.getAttribute("iq/query", "xmlns"));
  728.         assertEquals(this.nodeUnderTest.getNodeId(), actual.getElemCData("iq/query/host"));
  729.        
  730.     }
  731.    
  732.     @Test
  733.     /**
  734.      *            __________->successor->__________
  735.      *           /                                 \
  736.      * --->[nodeUnderTest]                      [otherNode]--->
  737.      *                                             /  /
  738.      *              [newNode]___->successor->_____/  /
  739.      *                  \                           /
  740.      *                   \____<-predecessor<-______/
  741.      *
  742.      *          ||              ||              ||
  743.      *         \  /            \  /            \  /
  744.      *          \/              \/              \/ 
  745.      *
  746.      *            ________->successor->_______  ________->successor->_______
  747.      *           /                            \/                            \
  748.      * --->[nodeUnderTest]                 [newNode]                    [otherNode]--->
  749.      *           \_______<-predecessor<-______/\_______<-predecessor<-______/  
  750.      *
  751.      * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
  752.      * key newNode (test.ru): 178.195.90.153.56.112.164.161.219.141.196.13.111.107.228.72.47.47.74.165
  753.      * key otherNode (test.org): 247.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21
  754.      *
  755.      * nodeUnderTest hast to send this message:
  756.      *
  757.      * <iq from="nodeUnderTest" to="otherNode" type="get" id="">
  758.      *  <query xmlns="dhtsearch:getpredecessor" />
  759.      * </iq>
  760.      *
  761.      * noderUnderTest then receives this message:
  762.      *  
  763.      * <iq from="otherNode" to="noderUnderTest" type="get" id"">
  764.      *  <query xmlns="dhtsearch.getpredecessor>
  765.      *   </host>newNode</host>
  766.      *  </query>
  767.      * </iq>
  768.      *
  769.      * noderUnderTest has to set his successor to newNode
  770.      * and to generate this message:
  771.      *
  772.      * <iq from="noderUnderTest" to="newNode" type="set" id="">
  773.      *  <query xmlns="dhtsearch:notifypredecessor>
  774.      *   <host>nodeUnderTest</host>
  775.      *  </query>
  776.      * </iq>
  777.      *
  778.      */
  779.     public void testStabilize4() throws TigaseStringprepException{
  780.         // set preconditions
  781.         ChordNeighborNode otherNode = new ChordNeighborNode("test.org", new ChordKey("test.org"));
  782.         this.nodeUnderTest.setSuccessor(otherNode);
  783.         ChordNeighborNode newNode = new ChordNeighborNode("test.ru", new ChordKey("test.ru"));
  784.         this.nodeUnderTest.setSuccessor(otherNode);
  785.        
  786.         // invoke stabilize
  787.         this.nodeUnderTest.stabilize(null);
  788.        
  789.         Packet actual = this.nodeUnderTest.testPackets.lastElement();
  790.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
  791.         assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
  792.         assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
  793.         assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
  794.  
  795.         // create message from otherNode
  796.         JID from = otherNode.getJID();
  797.         JID to = this.nodeUnderTest.getSelf().getJID();
  798.         String[] queryAttrValue = {"dhtsearch:getpredecessor"};
  799.         String[] queryAttrKey = {"xmlns"};
  800.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  801.         String[] iqAttrKey = {"from", "to", "id", "type"};
  802.         String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "result"};
  803.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  804.         iqElement.addChild(queryElement);
  805.         Element hostElement = new Element("host", newNode.getNodeId());
  806.         queryElement.addChild(hostElement);
  807.         Packet fsGet = Packet.packetInstance(iqElement);
  808.         this.nodeUnderTest.update(null, fsGet);
  809.        
  810.         // new successor has to be newNode
  811.         assertEquals(this.nodeUnderTest.getSuccessor().getNodeId(), newNode.getNodeId());
  812.        
  813.         actual = this.nodeUnderTest.testPackets.lastElement();
  814.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
  815.         assertEquals(newNode.getJID().toString(), actual.getAttribute("to"));
  816.         assertEquals(StanzaType.set.toString(), actual.getAttribute("type"));
  817.         assertEquals("dhtsearch:notifypredecessor", actual.getAttribute("iq/query", "xmlns"));
  818.         assertEquals(this.nodeUnderTest.getNodeId(), actual.getElemCData("iq/query/host"));
  819.     }
  820.    
  821.     @Test
  822.     /**
  823.      *            __________->successor->___________
  824.      *           /                                  \
  825.      * --->[otherNode]                      [nodeUnderTest]--->
  826.      *          \__________<-predecessor<-__________/
  827.      *
  828.      * otherNode: 48.15.146.226.136.49.193.49.157.246.215.143.216.240.146.169.155.246.48.193
  829.      * nodeUnderTest: 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
  830.      *
  831.      * nodeUnderTest receives this message:
  832.      *
  833.      * <iq from="otherNode" to="nodeUnderTest" type="get" id="">
  834.      *  <query xmlns="dhtsearch:getpredecessor" />
  835.      * </iq>
  836.      *
  837.      * nodeUnderTest replies with this message:
  838.      *  
  839.      * <iq from="nodeUnderTest" to="otherNode" type="result" id"">
  840.      *  <query xmlns="dhtsearch.getpredecessor">
  841.      *   </host>otherNode.getNodeID</host>
  842.      *  </query>
  843.      * </iq>
  844.      *
  845.      */
  846.     public void testStabilize5() throws TigaseStringprepException{
  847.         // set preconditions
  848.         ChordNeighborNode otherNode = new ChordNeighborNode("test.info", new ChordKey("test.info"));
  849.         this.nodeUnderTest.setPredecessor(otherNode);
  850.         // test preconditions
  851.         assertEquals(otherNode.getNodeId(), this.nodeUnderTest.getPredecessor().getNodeId());
  852.        
  853.         // create Message
  854.         JID from = otherNode.getJID();
  855.         JID to = this.nodeUnderTest.getSelf().getJID();
  856.         String[] queryAttrValue = {"dhtsearch:getpredecessor"};
  857.         String[] queryAttrKey = {"xmlns"};
  858.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  859.         String[] iqAttrKey = {"from", "to", "id", "type"};
  860.         String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "get"};
  861.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  862.         iqElement.addChild(queryElement);
  863.         Packet fsGet = Packet.packetInstance(iqElement);
  864.        
  865.         this.nodeUnderTest.update(null, fsGet);
  866.        
  867.         Packet actual = this.nodeUnderTest.testPackets.lastElement();
  868.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
  869.         assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
  870.         assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
  871.         assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
  872.        
  873.         // test postconditions
  874.         assertEquals(otherNode.getNodeId(), this.nodeUnderTest.getPredecessor().getNodeId());
  875.     }
  876.  
  877.     @Test
  878.     /**
  879.      *            __________->successor->__________
  880.      *           /                                 \
  881.      * --->[otherNode]                      [nodeUnderTest]--->
  882.      *                                  X__________/   
  883.      *
  884.      * otherNode (test.info): 48.15.146.226.136.49.193.49.157.246.215.143.216.240.146.169.155.246.48.193
  885.      * nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
  886.      *
  887.      * nodeUnderTest has to send this message:
  888.      *
  889.      * <iq from="test.info" to="mh.local" type="get" id="">
  890.      *  <query xmlns="dhtsearch:getpredecessor" />
  891.      * </iq>
  892.      *
  893.      * noderUnderTest then receives this message:
  894.      *  
  895.      * <iq from="mh.local" to="test.info" type="result" id"">
  896.      *  <query xmlns="dhtsearch.getpredecessor>
  897.      *   </host>hohost</host>
  898.      *  </query>
  899.      * </iq>
  900.      *
  901.      */
  902.     public void testStabilize6() throws TigaseStringprepException{
  903.         // set preconditions
  904.         ChordNeighborNode otherNode = new ChordNeighborNode("test.info", new ChordKey("test.info"));
  905.         this.nodeUnderTest.setSuccessor(null);
  906.         // test preconditions
  907.         // assertEquals(null, this.nodeUnderTest.getPredecessor().getNodeId()); TODO
  908.  
  909.         // create Message
  910.         JID from = otherNode.getJID();
  911.         JID to = this.nodeUnderTest.getSelf().getJID();
  912.         String[] queryAttrValue = {"dhtsearch:getpredecessor"};
  913.         String[] queryAttrKey = {"xmlns"};
  914.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  915.         String[] iqAttrKey = {"from", "to", "id", "type"};
  916.         String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "get"};
  917.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  918.         iqElement.addChild(queryElement);
  919.         Packet fsGet = Packet.packetInstance(iqElement);
  920.         this.nodeUnderTest.update(null, fsGet);
  921.        
  922.         // has to result in a getPredecessor result
  923.         Packet actual = this.nodeUnderTest.testPackets.get(0);
  924.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
  925.         assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
  926.         assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
  927.         assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
  928.         assertEquals("nohost", actual.getElemCData("iq/query/host"));
  929.     }
  930.  
  931.     @Test
  932.     /**
  933.      *            __________->successor->__________
  934.      *           /                                 \
  935.      * --->[otherNode]                      [nodeUnderTest]--->
  936.      *                                             /  /
  937.      *              [newNode]___->successor->_____/  /
  938.      *                  \                           /
  939.      *                   \____<-predecessor<-______/
  940.      *
  941.      *          ||              ||              ||
  942.      *         \  /            \  /            \  /
  943.      *          \/              \/              \/ 
  944.      *
  945.      *            ________->successor->_______  ________->successor->_______
  946.      *           /                            \/                            \
  947.      * --->[otherNode]                    [newNode]                     [nodeUnderTest]--->
  948.      *           \_______<-predecessor<-______/\_______<-predecessor<-______/  
  949.      *
  950.      * key newNode (test.de): 8.174.44.104.87.214.119.6.161.207.126.243.219.228.3.124.37.12.73.62
  951.      * key otherNode (test.gov): 109.49.60.79.34.195.186.64.247.69.125.71.235.179.82.175.114.36.116.11
  952.      * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
  953.      *
  954.      * otherNode has sends this message:
  955.      *
  956.      * <iq from="test.gov" to="mh.local" type="get" id="">
  957.      *  <query xmlns="dhtsearch:getpredecessor" />
  958.      * </iq>
  959.      *
  960.      * noderUnderTest then answers this message:
  961.      *  
  962.      * <iq from="mh.local" to="test.gov" type="result" id"">
  963.      *  <query xmlns="dhtsearch.getpredecessor>
  964.      *   </host>test.de</host>
  965.      *  </query>
  966.      * </iq>
  967.      *
  968.      *
  969.      */
  970.     public void testStabilize7() throws TigaseStringprepException{
  971.         // set preconditions
  972.         ChordNeighborNode otherNode = new ChordNeighborNode("test.gov", new ChordKey("test.gov"));
  973.         ChordNeighborNode newNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
  974.         this.nodeUnderTest.setPredecessor(newNode);
  975.         assertEquals(newNode.getNodeId(), this.nodeUnderTest.getPredecessor().getNodeId());
  976.        
  977.         // create Message
  978.         JID from = otherNode.getJID();
  979.         JID to = this.nodeUnderTest.getSelf().getJID();
  980.         String[] queryAttrValue = {"dhtsearch:getpredecessor"};
  981.         String[] queryAttrKey = {"xmlns"};
  982.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  983.         String[] iqAttrKey = {"from", "to", "id", "type"};
  984.         String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "get"};
  985.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  986.         iqElement.addChild(queryElement);
  987.         Packet fsGet = Packet.packetInstance(iqElement);
  988.         this.nodeUnderTest.update(null, fsGet);
  989.        
  990.         Packet actual = this.nodeUnderTest.testPackets.get(0);
  991.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
  992.         assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
  993.         assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
  994.         assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
  995.         assertEquals(newNode.getNodeId(), actual.getElemCData("iq/query/host"));
  996.  
  997.         assertEquals(newNode.getNodeId(), this.nodeUnderTest.getPredecessor().getNodeId());
  998.     }
  999.    
  1000.     @Test
  1001.     /**
  1002.      *            __________->successor->__________
  1003.      *           /                                 \
  1004.      * --->[otherNode1]                        [otherNode2]--->
  1005.      *                                             /  /
  1006.      *              [nodeUnderTest]_->successor->_/  /
  1007.      *                  \                           /
  1008.      *                   \____<-predecessor<-______/
  1009.      *
  1010.      *          ||              ||              ||
  1011.      *         \  /            \  /            \  /
  1012.      *          \/              \/              \/ 
  1013.      *
  1014.      *            ________->successor->_______  ________->successor->_______
  1015.      *           /                            \/                            \
  1016.      * --->[otherNode1]                 [nodeUnderTest]                 [otherNode2]--->
  1017.      *           \_______<-predecessor<-______/\_______<-predecessor<-______/  
  1018.      *
  1019.      * key otherNode1 (test.de): 8.174.44.104.87.214.119.6.161.207.126.243.219.228.3.124.37.12.73.62
  1020.      * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
  1021.      * key otherNode2 (test.co.uk): 254.112.97.135.41.183.33.119.107.214.103.64.56.23.130.102.146.130.226.73
  1022.      *
  1023.      * otherNode has sends this message:
  1024.      *
  1025.      * <iq from="test.de" to="mh.local" type="set" id="">
  1026.      *  <query xmlns="dhtsearch:notifypredecessor">
  1027.      *   <host>test.de</host>
  1028.      * </iq>
  1029.      *
  1030.      * nodeUnderTest has to set his predecessor to otherNode1
  1031.      *
  1032.      *
  1033.      */
  1034.     public void testStabilize8() throws TigaseStringprepException{
  1035. //      // set preconditions
  1036.         ChordNeighborNode otherNode1 = new ChordNeighborNode("test.de", new ChordKey("test.de"));
  1037.         ChordNeighborNode otherNode2 = new ChordNeighborNode("test.co.uk", new ChordKey("test.co.uk"));
  1038.         this.nodeUnderTest.setPredecessor(null);
  1039.         this.nodeUnderTest.setSuccessor(otherNode2);
  1040.         // test preconditions
  1041.         assertTrue(this.nodeUnderTest.getPredecessor() == null);
  1042.         assertTrue(this.nodeUnderTest.getSuccessor().getNodeId().equals(otherNode2.getNodeId()));
  1043.        
  1044.         //create Message
  1045.         JID from = otherNode1.getJID();
  1046.         JID to = this.nodeUnderTest.getSelf().getJID();
  1047.         String[] queryAttrValue = {"dhtsearch:notifypredecessor"};
  1048.         String[] queryAttrKey = {"xmlns"};
  1049.         Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
  1050.         String[] iqAttrKey = {"from", "to", "id", "type"};
  1051.         String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "set"};
  1052.         Element hostElement = new Element("host", otherNode1.getNodeId());
  1053.         queryElement.addChild(hostElement);
  1054.         Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
  1055.         iqElement.addChild(queryElement);
  1056.         Packet fsGet = Packet.packetInstance(iqElement);
  1057.         this.nodeUnderTest.update(null, fsGet);
  1058.        
  1059.         assertEquals(otherNode1.getNodeId(), this.nodeUnderTest.getPredecessor().getNodeId());
  1060.     }
  1061.    
  1062.     @Test
  1063.     /**
  1064.      * tests the initial fingertable after fix finger operation
  1065.      * without answers
  1066.      *
  1067.      * preconditions:
  1068.      * - number of openOperations: 0
  1069.      *
  1070.      * postconditions:
  1071.      * - number of openOperations: 160
  1072.      * - each finger has to be the node itself
  1073.      *
  1074.      */
  1075.     public void testFingerTable0() throws TigaseStringprepException{
  1076.         this.nodeUnderTest.fixFingers();
  1077.         assertEquals(160, this.nodeUnderTest.getOpenOperations().size());
  1078.         FingerTable fingerTabel = this.nodeUnderTest.getFingerTable();
  1079.         for (int j = 0; j < 160; j++) {
  1080.             assertEquals("mh.local", fingerTabel.getFinger(j).getNode().getNodeId());
  1081.         }
  1082.     }
  1083.    
  1084.     @Test
  1085.     /**
  1086.      * tests the initial fingertable after fix finger operation
  1087.      * with answers
  1088.      *
  1089.      * preconditions:
  1090.      * - number of openOperations: 0
  1091.      *
  1092.      * postconditions:
  1093.      * - number of openOperations: 0
  1094.      * - each finger has to be the node itself
  1095.      * - message in testPacket has to be the stanza findsuccessor for the last finger
  1096.      *
  1097.      * last message:
  1098.      * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="get">
  1099.      *  <query xmlns="dhtsearch.findsuccessor">
  1100.      *   <key>mh.local</key>
  1101.      *  </query>
  1102.      * </iq>
  1103.      *
  1104.      * answer all messages
  1105.      * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="result"
  1106.      *
  1107.      */
  1108.     public void testFingerTable1() throws TigaseStringprepException{
  1109.         this.nodeUnderTest.fixFingers();
  1110.         assertEquals(160, this.nodeUnderTest.getOpenOperations().size());
  1111.         FingerTable fingerTabel = this.nodeUnderTest.getFingerTable();
  1112.         for (int j = 0; j < 160; j++) {
  1113.             assertEquals("mh.local", fingerTabel.getFinger(j).getNode().getNodeId());
  1114.         }
  1115.        
  1116.         Packet actual = this.nodeUnderTest.testPackets.lastElement();
  1117.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(),actual.getAttribute("from"));
  1118.         assertEquals(this.nodeUnderTest.getSelf().getJID().toString(),actual.getAttribute("to"));
  1119.         assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
  1120.         assertEquals("0", actual.getAttribute("seq"));
  1121.         assertEquals("dhtsearch:findsuccessor", actual.getAttribute("iq/query", "xmlns"));
  1122.         assertEquals(this.nodeUnderTest.getFingerTable().getFinger(159).getStart().toString(), actual.getElemCData("iq/query/key"));
  1123.         assertEquals( 159, this.nodeUnderTest.getOpenOperations().get(UUID.fromString(actual.getAttribute("id"))).getParameter("finger"));
  1124.        
  1125.         // check all packets fot the right key
  1126.         for (int i = 0; i < this.nodeUnderTest.getFingerTable().size(); i++) {
  1127.             assertEquals(this.nodeUnderTest.getFingerTable().getFinger(i).getStart().toString(), this.nodeUnderTest.testPackets.get(i).getElemCData("iq/query/key"));
  1128.         }
  1129.        
  1130.         // write all the messages to a temporary vector
  1131.         Vector<Packet> messages = (Vector<Packet>) this.nodeUnderTest.testPackets.clone();
  1132.         this.nodeUnderTest.testPackets.clear();
  1133.         // answer all packets
  1134.         for (int i = 0; i < messages.size(); i++) {
  1135.             this.nodeUnderTest.update(null, messages.get(i));
  1136.         }
  1137.        
  1138.         // test all the resulting packets
  1139.         for (int i = 0; i < this.nodeUnderTest.testPackets.size(); i++) {
  1140.             Packet actual1 = this.nodeUnderTest.testPackets.get(i);
  1141.             assertEquals(this.nodeUnderTest.getNodeId(), actual1.getElemCData("iq/query/host"));
  1142.             assertEquals(StanzaType.result.toString(), actual1.getAttribute("type"));
  1143.             assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual1.getAttribute("to"));
  1144.             assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual1.getAttribute("from"));
  1145.             assertEquals("0", actual1.getAttribute("seq"));
  1146.             assertEquals("dhtsearch:findsuccessor", actual1.getAttribute("iq/query", "xmlns"));
  1147.         }
  1148.     }
  1149.     /**
  1150.      * method for lookin up keys
  1151.      */
  1152.     public void keys(){
  1153.         System.out.println(new ChordKey("mh.local"));
  1154.         System.out.println(new ChordKey("test.de"));
  1155.         System.out.println(new ChordKey("test.info"));
  1156.         System.out.println(new ChordKey("test.ru"));
  1157.         System.out.println(new ChordKey("test.com"));
  1158.         System.out.println(new ChordKey("test.org"));
  1159.         System.out.println(new ChordKey("test.gov"));
  1160.         System.out.println(new ChordKey("test.co.uk"));
  1161.     }
  1162. }
Add Comment
Please, Sign In to add comment