Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dons.chord.test;
- import static org.junit.Assert.*;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.UUID;
- import java.util.Vector;
- import org.junit.Before;
- import org.junit.Test;
- import sun.security.x509.OtherName;
- import tigase.server.Packet;
- import tigase.util.TigaseStringprepException;
- import tigase.xml.Element;
- import tigase.xmpp.JID;
- import tigase.xmpp.StanzaType;
- import dons.ParameterObject;
- import dons.chord.ChordKey;
- import dons.chord.ChordNeighborNode;
- import dons.chord.ChordNode;
- import dons.chord.FingerTable;
- import dons.chord.PendingFSOperation;
- public class ChordNodeTest {
- ChordNode nodeUnderTest;
- ChordKey nodeKey;
- String hostname;
- @Before
- public void createChordNode(){
- hostname = "mh.local";
- this.nodeUnderTest = new ChordNode(hostname, null);
- this.nodeUnderTest.test = true;
- this.nodeKey = new ChordKey(hostname);
- }
- @Test
- public void testCreateChordNode() {
- assertEquals(hostname, nodeUnderTest.getNodeId());
- assertEquals(nodeKey.toString(),nodeUnderTest.getNodeKey().toString());
- //assertEquals(nodeUnderTest.getPredecessor(), null);
- assertEquals(nodeUnderTest.getSuccessor().getNodeId(), hostname);
- assertEquals("dhtsearch@mh.local", nodeUnderTest.getSelf().getJID().toString());
- //System.out.println(node.printFingerTable());
- }
- // createFindSuccessorGet
- @Test
- public void testCreateFindSuccessorGet0(){
- String ID = UUID.randomUUID().toString();
- nodeUnderTest.createFindSuccessorGet(nodeUnderTest.getSelf(), nodeKey, ID, "0");
- Packet actual = nodeUnderTest.testPackets.get(0);
- assertEquals(StanzaType.get.toString(), actual.getType().toString());
- assertEquals(nodeUnderTest.getSelf().getJID().toString() ,actual.getFrom().toString());
- assertEquals(nodeUnderTest.getSelf().getJID().toString(), actual.getTo().toString());
- assertEquals(ID, actual.getAttribute("id"));
- assertEquals(nodeKey.toString(), actual.getElemCData("iq/query/key"));
- assertEquals("0", actual.getAttribute("seq"));
- }
- @Test
- public void testCreateFindSuccessorGet1(){
- ChordNode otherNode = new ChordNode("test.de", null);
- String ID = UUID.randomUUID().toString();
- nodeUnderTest.createFindSuccessorGet(otherNode.getSelf(), nodeKey, ID, "0");
- Packet actual = nodeUnderTest.testPackets.get(0);
- assertEquals(StanzaType.get.toString(), actual.getType().toString());
- assertEquals(nodeUnderTest.getSelf().getJID().toString() ,actual.getFrom().toString());
- assertEquals(otherNode.getSelf().getJID().toString(), actual.getTo().toString());
- assertEquals(ID, actual.getAttribute("id"));
- assertEquals(nodeKey.toString(), actual.getElemCData("iq/query/key"));
- assertEquals("0", actual.getAttribute("seq"));
- }
- @Test
- /**
- * generated Message:
- * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@test.de" type="get">
- * <query xmlns="dhtsearch.findsuccessor">
- * <key>.....</key>
- * </query>
- * </iq>
- *
- * answered with:
- * <iq id="xyz" seq="0" from="dhtsearch@test.de" to="dhtsearch@mh.local" type="result">
- * <query xmlns="dhtsearch.findsuccessor">
- * <host>test.de</host>
- * </query>
- * </iq>
- *
- * precondition after triggered join method:
- * - size of openOperations: 1
- * - generated Message is in testPacket
- * - size of getPendingFSOperations: 0
- *
- * postcondition:
- * - size if openOperations: 0
- * - size of getPendingFSOperation: 0
- * - successor = test.de
- *
- */
- public void testJoin0() throws TigaseStringprepException{
- ChordNode otherNode = new ChordNode("test.de", null);
- this.nodeUnderTest.join(new ChordNeighborNode(otherNode.getNodeId(), otherNode.getNodeKey()));
- assertEquals(1,this.nodeUnderTest.getOpenOperations().size());
- assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
- // test outgoing Packet
- Packet actual = nodeUnderTest.testPackets.get(0);
- assertEquals(StanzaType.get.toString(), actual.getType().toString());
- assertEquals("0", actual.getAttribute("seq"));
- assertEquals(otherNode.getSelf().getJID().toString(), actual.getTo().toString());
- assertEquals(nodeUnderTest.getSelf().getJID().toString(), actual.getFrom().toString());
- assertEquals(actual.getAttribute("iq/query", "xmlns"), "dhtsearch:findsuccessor");
- assertEquals(actual.getElemCData("iq/query/key"), this.nodeUnderTest.getNodeKey().toString());
- // generate incomming packet
- Element host = new Element("host", otherNode.getNodeId());
- JID from = otherNode.getSelf().getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- Element hostElement = new Element("host", otherNode.getNodeId());
- String[] queryAttrValue = {"dhtsearch:findsuccessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- queryElement.addChild(hostElement);
- int seq = 0;
- if(seq != 0) // catch the basic case: self is result
- seq--;
- String strSeq = String.valueOf(seq);
- String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), actual.getAttribute("id"), strSeq, "result"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsResult = null;
- fsResult = Packet.packetInstance(iqElement);
- // test the
- this.nodeUnderTest.update(null, fsResult);
- assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
- assertEquals(otherNode.getNodeId(), this.nodeUnderTest.getSuccessor().getNodeId());
- assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
- }
- @Test
- /**
- * generated Message:
- * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="get">
- * <query xmlns="dhtsearch.findsuccessor">
- * <key>.....</key>
- * </query>
- * </iq>
- *
- * answered with:
- * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="result">
- * <query xmlns="dhtsearch.findsuccessor">
- * <host>mh.local</host>
- * </query>
- * </iq>
- *
- * preconditions
- * - size of openOperations: 0
- * - size of getPendingFSOperations: 0
- *
- * postcondition:s
- * - size if openOperations: 0
- * - size of getPendingFSOperation: 0
- * - resultMessage is in testpacket
- *
- */
- public void testReceiveGetMessage0() throws TigaseStringprepException{
- assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
- assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
- // generate incomming packet
- String ID = UUID.randomUUID().toString();
- Element key = new Element("key", this.nodeUnderTest.getNodeKey().toString());
- JID from = this.nodeUnderTest.getSelf().getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:findsuccessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- queryElement.addChild(key);
- int seq = 0;
- String strSeq = String.valueOf(seq);
- String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), ID, strSeq, "get"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsResult = null;
- fsResult = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsResult);
- // test resultMessage
- Packet actual = this.nodeUnderTest.testPackets.get(0);
- assertEquals(actual.getAttribute("id"), ID);
- assertEquals(actual.getAttribute("seq"), "0");
- assertEquals(actual.getAttribute("type"), StanzaType.result.toString());
- assertEquals(actual.getElemCData("iq/query/host"), this.nodeUnderTest.getNodeId());
- assertEquals(actual.getAttribute("iq/query", "xmlns"), "dhtsearch:findsuccessor");
- assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
- assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
- }
- @Test
- /**
- * ---->[noderUnderTest]--|key|-->[othernode]---->
- * key is between nodeUnderTest and its successor and nodeUnderTest starts the search
- *
- * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
- * key otherNode (test.org): 247.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21
- *
- * generated Message:
- * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="get">
- * <query xmlns="dhtsearch.findsuccessor">
- * <key>200.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132</key>
- * </query>
- * </iq>
- *
- * answered with:
- * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="result">
- * <query xmlns="dhtsearch.findsuccessor">
- * <host>test.org</host>
- * </query>
- * </iq>
- *
- * preconditions
- * - size of openOperations: 0
- * - size of getPendingFSOperations: 0
- *
- * postcondition:s
- * - size if openOperations: 0
- * - size of getPendingFSOperation: 0
- * - resultMessage is in testpacket
- *
- */
- public void testReceiveGetMessage1() throws TigaseStringprepException{
- ChordNeighborNode otherNode = new ChordNeighborNode("test.org", new ChordKey("test.org"));
- this.nodeUnderTest.setSuccessor(otherNode);
- // generate incomming packet
- String ID = UUID.randomUUID().toString();
- 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");
- JID from = this.nodeUnderTest.getSelf().getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:findsuccessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- queryElement.addChild(key);
- int seq = 0;
- String strSeq = String.valueOf(seq);
- String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), ID, strSeq, "get"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsResult = null;
- fsResult = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsResult);
- // rest result message // TODO flip arguments
- Packet actual = this.nodeUnderTest.testPackets.get(0);
- assertEquals(actual.getAttribute("id"), ID);
- assertEquals(actual.getAttribute("seq"), "0");
- assertEquals(actual.getAttribute("type"), StanzaType.result.toString());
- assertEquals(actual.getElemCData("iq/query/host"), otherNode.getNodeId());
- assertEquals(actual.getAttribute("iq/query", "xmlns"), "dhtsearch:findsuccessor");
- assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
- assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
- }
- @Test
- /**
- * ---->[noderUnderTest]--|key|-->[othernode]---->
- * key is between nodeUnderTest and its successor and a node before noderUnderTest starts the search
- *
- * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
- * key otherNode (test.org): 247.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21
- *
- * generated Message:
- * <iq id="xyz" seq="5" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="get">
- * <query xmlns="dhtsearch.findsuccessor">
- * <key>200.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132</key>
- * </query>
- * </iq>
- *
- * answered with:
- * <iq id="xyz" seq="4" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="result">
- * <query xmlns="dhtsearch.findsuccessor">
- * <host>test.org</host>
- * </query>
- * </iq>
- *
- * preconditions
- * - size of openOperations: 0
- * - size of getPendingFSOperations: 0
- *
- * postcondition:s
- * - size if openOperations: 0
- * - size of getPendingFSOperation: 0
- * - resultMessage is in testpacket
- *
- */
- public void testReceiveGetMessage2() throws TigaseStringprepException{
- ChordNeighborNode otherNode = new ChordNeighborNode("test.org", new ChordKey("test.org"));
- this.nodeUnderTest.setSuccessor(otherNode);
- // generate incomming packet
- String ID = UUID.randomUUID().toString();
- 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");
- JID from = JID.jidInstance("dhtseatch@testserver3.com");
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:findsuccessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- queryElement.addChild(key);
- int seq = 5;
- String strSeq = String.valueOf(seq);
- String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), ID, strSeq, "get"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsResult = null;
- fsResult = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsResult);
- // rest result message
- Packet actual = this.nodeUnderTest.testPackets.get(0);
- assertEquals(ID, actual.getAttribute("id"));
- assertEquals("4", actual.getAttribute("seq"));
- assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
- assertEquals(otherNode.getNodeId(), actual.getElemCData("iq/query/host"));
- assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
- assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
- }
- @Test
- /**
- * ---->[otherNode1]---->[noderUnderTest]---->[otherNode2]--|key|-->
- * key is after othernode 2 and othernode1 sends a get findsuccessor so nodeUnderTest has to forward
- * this message
- * key otherNode1 (test.net):9.76.81.242.102.55.25.149.96.141.200.212.100.112.162.48.242.198.165.66
- * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
- * key otherNode (test.org): 247.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21
- *
- * generated Message:
- * <iq id="xyz" seq="5" from="test.net" to="mh.local" type="get">
- * <query xmlns="dhtsearch.findsuccessor">
- * <key>248.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132</key>
- * </query>
- * </iq>
- *
- * answered with:
- * <iq id="xyz" seq="6" from="mh.local" to="test.org" type="get">
- * <query xmlns="dhtsearch.findsuccessor">
- * <key>248.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132</key>
- * </query>
- * </iq>
- *
- * preconditions
- * - size of openOperations: 0
- * - size of getPendingFSOperations: 0
- *
- * postcondition:s
- * - size if openOperations: 0
- * - size of getPendingFSOperation: 1
- * - resultMessage is in testpacket
- *
- */
- public void testReceiveGetMessage3() throws TigaseStringprepException{
- ChordNeighborNode otherNode1 = new ChordNeighborNode("test.net", new ChordKey("test.net"));
- this.nodeUnderTest.setPredecessor(otherNode1);
- ChordNeighborNode otherNode2 = new ChordNeighborNode("test.org", new ChordKey("test.org"));
- this.nodeUnderTest.setSuccessor(otherNode2);
- // generate incomming packet
- String ID = UUID.randomUUID().toString();
- 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");
- JID from = JID.jidInstance("dhtsearch@test.net");
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:findsuccessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- queryElement.addChild(key);
- int seq = 5;
- String strSeq = String.valueOf(seq);
- String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), ID, strSeq, "get"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsResult = null;
- fsResult = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsResult);
- // rest result message
- Packet actual = this.nodeUnderTest.testPackets.get(0);
- assertEquals(ID, actual.getAttribute("id"));
- assertEquals("6", actual.getAttribute("seq"));
- assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
- 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"));
- assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
- assertEquals(1, this.nodeUnderTest.getPendingFSOperations().size());
- }
- @Test
- /**
- * --->[otherNode1]---->[noderUnderTest]---->[otherNode2]--|key|-->
- * key is after othernode 2 and a node before nodeUnderTest asks for a key so nodeUnder test has to
- * forward the result
- * key otherNode1 (test.net):9.76.81.242.102.55.25.149.96.141.200.212.100.112.162.48.242.198.165.66
- * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
- * key otherNode2 (test.org): 247.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21
- *
- * generated Message:
- *
- * <id id="xyz" seq="5" from="test.net" to"mh.local" type="get">
- * <query xmlns="dhtsearch.findsuccessor">
- * <key>257.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21</key>
- * </query>
- * </id>
- *
- * Message send to nodeUnderTest:
- * <iq id="xyz" seq="5" from="test.org" to="mh.local" type="result">
- * <query xmlns="dhtsearch.findsuccessor">
- * <host>test.ru</host>
- * </query>
- * </iq>
- *
- * answered with:
- * <iq id="xyz" seq="4" from="mh.local" to="test.net" type="result">
- * <query xmlns="dhtsearch.findsuccessor">
- * <host>test.ru</host>
- * </query>
- * </iq>
- *
- * preconditions
- * - size of openOperations: 0
- * - size of getPendingFSOperations: 1
- *
- * postcondition:s
- * - size if openOperations: 0
- * - size of getPendingFSOperation: 0
- * - resultMessage is in testpacket
- *
- */
- public void testReceiveResultMessage0() throws TigaseStringprepException{
- ChordNeighborNode otherNode1 = new ChordNeighborNode("test.net", new ChordKey("test.net"));
- this.nodeUnderTest.setPredecessor(otherNode1);
- ChordNeighborNode otherNode2 = new ChordNeighborNode("test.org", new ChordKey("test.org"));
- this.nodeUnderTest.setSuccessor(otherNode2);
- // generate packet for fsPending-Object
- String ID = UUID.randomUUID().toString();
- 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");
- JID from = otherNode1.getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:findsuccessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- queryElement.addChild(key);
- int seq = 5;
- String strSeq = String.valueOf(seq);
- String[] iqAttrKey = {"from", "to", "id", "seq", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), ID, strSeq, "get"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsResult = null;
- fsResult = Packet.packetInstance(iqElement);
- // add the package as an pending operation
- PendingFSOperation pendingFs = new PendingFSOperation(fsResult);
- this.nodeUnderTest.getPendingFSOperations().put(ID, pendingFs);
- //test preconditions
- assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
- assertEquals(1, this.nodeUnderTest.getPendingFSOperations().size());
- // generate incomming packet
- Element key_1 = new Element("host", "test.ru");
- JID from_1 = otherNode2.getJID();
- JID to_1 = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue_1 = {"dhtsearch:findsuccessor"};
- String[] queryAttrKey_1 = {"xmlns"};
- Element queryElement_1 = new Element("query", queryAttrKey_1, queryAttrValue_1);
- queryElement_1.addChild(key_1);
- int seq_1 = 5;
- String strSeq_1 = String.valueOf(seq_1);
- String[] iqAttrKey_1 = {"from", "to", "id", "seq", "type"};
- String[] iqAttrValue_1 = {from_1.toString(), to_1.toString(), ID, strSeq_1, "result"};
- Element iqElement_1 = new Element("iq", iqAttrKey_1, iqAttrValue_1);
- iqElement_1.addChild(queryElement_1);
- Packet fsResult_1 = null;
- fsResult_1 = Packet.packetInstance(iqElement_1);
- this.nodeUnderTest.update(null, fsResult_1);
- // test result message
- Packet actual = this.nodeUnderTest.testPackets.get(0);
- assertEquals(ID, actual.getAttribute("id"));
- assertEquals("4", actual.getAttribute("seq"));
- assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
- assertEquals("test.ru", actual.getElemCData("iq/query/host"));
- assertEquals(0,this.nodeUnderTest.getOpenOperations().size());
- assertEquals(0, this.nodeUnderTest.getPendingFSOperations().size());
- }
- @Test
- /**
- * test the message format for a stabilize result Message (getPredecessor produces this message)
- *
- * incoming Message:
- * <iq from="successor.nodeUnderTest" to="nodeUnderTest" id="xyz" type="get">
- * <query xmlns"dhtSearch:getPredecessor />
- * </query>
- * </iq>
- *
- *
- * <iq from="nodeUnderTest" to="successor.nodeUnderTest" id="xyz" type="result">
- * <query xmlns"dhtSearch:getPredecessor" />
- * <host>nodeUnderTest.predecessor</host>
- * </query>
- * </iq>
- */
- public void testGetPredecessorMessage() throws TigaseStringprepException{
- // set preconditions
- ChordNeighborNode otherNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
- this.nodeUnderTest.setPredecessor(otherNode);
- // construct incomming message
- JID from = otherNode.getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:getpredecessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- String[] iqAttrKey = {"from", "to", "id", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "get"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsGet = Packet.packetInstance(iqElement);
- this.nodeUnderTest.getPredecessor(fsGet);
- Packet actual = this.nodeUnderTest.testPackets.get(0);
- assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
- assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
- assertEquals(otherNode.getNodeId(), actual.getElemCData("iq/query/host"));
- }
- @Test
- /**
- * test the message format for a stabilize get Message
- * <iq from="nodeUnderTest" to="successor.nodeUnderTest" id="xyz" type="get">
- * <query xmlns="dhtsearch:getPredecessor />
- * </iq>
- */
- public void testStabilize0(){
- // set preconditions
- ChordNeighborNode otherNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
- this.nodeUnderTest.setSuccessor(otherNode);
- // invoke method
- this.nodeUnderTest.stabilize(null);
- Packet actual = this.nodeUnderTest.testPackets.get(0);
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
- assertEquals(this.nodeUnderTest.getSuccessor().getJID().toString(), actual.getAttribute("to"));
- assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
- assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
- }
- @Test
- /**
- * test the message format for a stabilize result Message
- * <iq from="successor.nodeUnderTest" id="xyz" type="result">
- * <query xmlns"dhtSearch:getPredecessor />
- * <host>successor.predecessor</host>
- * </query>
- * </iq>
- */
- public void testStabilize1() throws TigaseStringprepException{
- // set preconditions
- ChordNeighborNode otherNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
- this.nodeUnderTest.setPredecessor(otherNode);
- // generate test get message
- JID from = otherNode.getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:getpredecessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- String[] iqAttrKey = {"from", "to", "id", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "get"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsGet = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsGet);
- // check result
- Packet actual = this.nodeUnderTest.testPackets.get(0);
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
- assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
- assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
- assertEquals("test.de", actual.getElemCData("iq/query/host"));
- }
- @Test
- /**
- * __________->successor->__________
- * / \
- * --->[nodeUnderTest] [otherNode]--->
- * \__________<-predecessor<-__________/
- *
- * nodeUnderTest hast to send this message:
- *
- * <iq from="nodeUnderTest" to="otherNode" type="get" id="">
- * <query xmlns="dhtsearch:getpredecessor" />
- * </iq>
- *
- * noderUnderTest then receives this message:
- *
- * <iq from="otherNode" to="noderUnderTest" type="result" id"">
- * <query xmlns="dhtsearch.getpredecessor>
- * </host>nodeUnderTest.getNodeID</host>
- * </query>
- * </iq>
- *
- */
- public void testStabilize2() throws TigaseStringprepException{
- // set preconditions
- ChordNeighborNode otherNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
- this.nodeUnderTest.setSuccessor(otherNode);
- // invoke stabilize
- this.nodeUnderTest.stabilize(null);
- // test the resulting package
- Packet actual = this.nodeUnderTest.testPackets.get(0);
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
- assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
- assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
- assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
- // construct answer from otherNode
- JID from = otherNode.getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:getpredecessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- String[] iqAttrKey = {"from", "to", "id", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "result"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Element hostElement = new Element("host", "mh.local");
- queryElement.addChild(hostElement);
- Packet fsGet = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsGet);
- assertEquals(otherNode.getJID(), this.nodeUnderTest.getSuccessor().getJID());
- }
- @Test
- /**
- * __________->successor->__________
- * / \
- * --->[nodeUnderTest] [otherNode]--->
- * X__________/
- *
- * nodeUnderTest has to send this message:
- *
- * <iq from="nodeUnderTest" to="otherNode" type="get" id="">
- * <query xmlns="dhtsearch:getpredecessor" />
- * </iq>
- *
- *
- * noderUnderTest then receives this message:
- *
- * <iq from="otherNode" to="noderUnderTest" type="get" id"">
- * <query xmlns="dhtsearch.getpredecessor>
- * </host>hohost</host>
- * </query>
- * </iq>
- *
- */
- public void testStabilize3() throws TigaseStringprepException{
- // set preconditions
- ChordNeighborNode otherNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
- this.nodeUnderTest.setSuccessor(otherNode);
- // invoke stabilize
- this.nodeUnderTest.stabilize(null);
- // test the resulting package
- Packet actual = this.nodeUnderTest.testPackets.lastElement();
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
- assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
- assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
- assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
- // construct the answert from otherNode
- JID from = otherNode.getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:getpredecessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- String[] iqAttrKey = {"from", "to", "id", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "result"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Element hostElement = new Element("host", "nohost");
- queryElement.addChild(hostElement);
- Packet fsGet = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsGet);
- // test
- assertEquals(this.nodeUnderTest.getSuccessor().getNodeId(), otherNode.getNodeId());
- // has to result in a notify predecessor Message
- actual = this.nodeUnderTest.testPackets.lastElement();
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
- assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
- assertEquals(StanzaType.set.toString(), actual.getAttribute("type"));
- assertEquals("dhtsearch:notifypredecessor", actual.getAttribute("iq/query", "xmlns"));
- assertEquals(this.nodeUnderTest.getNodeId(), actual.getElemCData("iq/query/host"));
- }
- @Test
- /**
- * __________->successor->__________
- * / \
- * --->[nodeUnderTest] [otherNode]--->
- * / /
- * [newNode]___->successor->_____/ /
- * \ /
- * \____<-predecessor<-______/
- *
- * || || ||
- * \ / \ / \ /
- * \/ \/ \/
- *
- * ________->successor->_______ ________->successor->_______
- * / \/ \
- * --->[nodeUnderTest] [newNode] [otherNode]--->
- * \_______<-predecessor<-______/\_______<-predecessor<-______/
- *
- * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
- * key newNode (test.ru): 178.195.90.153.56.112.164.161.219.141.196.13.111.107.228.72.47.47.74.165
- * key otherNode (test.org): 247.82.28.194.245.58.2.121.103.78.172.33.47.155.34.214.50.115.95.21
- *
- * nodeUnderTest hast to send this message:
- *
- * <iq from="nodeUnderTest" to="otherNode" type="get" id="">
- * <query xmlns="dhtsearch:getpredecessor" />
- * </iq>
- *
- * noderUnderTest then receives this message:
- *
- * <iq from="otherNode" to="noderUnderTest" type="get" id"">
- * <query xmlns="dhtsearch.getpredecessor>
- * </host>newNode</host>
- * </query>
- * </iq>
- *
- * noderUnderTest has to set his successor to newNode
- * and to generate this message:
- *
- * <iq from="noderUnderTest" to="newNode" type="set" id="">
- * <query xmlns="dhtsearch:notifypredecessor>
- * <host>nodeUnderTest</host>
- * </query>
- * </iq>
- *
- */
- public void testStabilize4() throws TigaseStringprepException{
- // set preconditions
- ChordNeighborNode otherNode = new ChordNeighborNode("test.org", new ChordKey("test.org"));
- this.nodeUnderTest.setSuccessor(otherNode);
- ChordNeighborNode newNode = new ChordNeighborNode("test.ru", new ChordKey("test.ru"));
- this.nodeUnderTest.setSuccessor(otherNode);
- // invoke stabilize
- this.nodeUnderTest.stabilize(null);
- Packet actual = this.nodeUnderTest.testPackets.lastElement();
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
- assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
- assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
- assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
- // create message from otherNode
- JID from = otherNode.getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:getpredecessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- String[] iqAttrKey = {"from", "to", "id", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "result"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Element hostElement = new Element("host", newNode.getNodeId());
- queryElement.addChild(hostElement);
- Packet fsGet = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsGet);
- // new successor has to be newNode
- assertEquals(this.nodeUnderTest.getSuccessor().getNodeId(), newNode.getNodeId());
- actual = this.nodeUnderTest.testPackets.lastElement();
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
- assertEquals(newNode.getJID().toString(), actual.getAttribute("to"));
- assertEquals(StanzaType.set.toString(), actual.getAttribute("type"));
- assertEquals("dhtsearch:notifypredecessor", actual.getAttribute("iq/query", "xmlns"));
- assertEquals(this.nodeUnderTest.getNodeId(), actual.getElemCData("iq/query/host"));
- }
- @Test
- /**
- * __________->successor->___________
- * / \
- * --->[otherNode] [nodeUnderTest]--->
- * \__________<-predecessor<-__________/
- *
- * otherNode: 48.15.146.226.136.49.193.49.157.246.215.143.216.240.146.169.155.246.48.193
- * nodeUnderTest: 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
- *
- * nodeUnderTest receives this message:
- *
- * <iq from="otherNode" to="nodeUnderTest" type="get" id="">
- * <query xmlns="dhtsearch:getpredecessor" />
- * </iq>
- *
- * nodeUnderTest replies with this message:
- *
- * <iq from="nodeUnderTest" to="otherNode" type="result" id"">
- * <query xmlns="dhtsearch.getpredecessor">
- * </host>otherNode.getNodeID</host>
- * </query>
- * </iq>
- *
- */
- public void testStabilize5() throws TigaseStringprepException{
- // set preconditions
- ChordNeighborNode otherNode = new ChordNeighborNode("test.info", new ChordKey("test.info"));
- this.nodeUnderTest.setPredecessor(otherNode);
- // test preconditions
- assertEquals(otherNode.getNodeId(), this.nodeUnderTest.getPredecessor().getNodeId());
- // create Message
- JID from = otherNode.getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:getpredecessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- String[] iqAttrKey = {"from", "to", "id", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "get"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsGet = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsGet);
- Packet actual = this.nodeUnderTest.testPackets.lastElement();
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
- assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
- assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
- assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
- // test postconditions
- assertEquals(otherNode.getNodeId(), this.nodeUnderTest.getPredecessor().getNodeId());
- }
- @Test
- /**
- * __________->successor->__________
- * / \
- * --->[otherNode] [nodeUnderTest]--->
- * X__________/
- *
- * otherNode (test.info): 48.15.146.226.136.49.193.49.157.246.215.143.216.240.146.169.155.246.48.193
- * nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
- *
- * nodeUnderTest has to send this message:
- *
- * <iq from="test.info" to="mh.local" type="get" id="">
- * <query xmlns="dhtsearch:getpredecessor" />
- * </iq>
- *
- * noderUnderTest then receives this message:
- *
- * <iq from="mh.local" to="test.info" type="result" id"">
- * <query xmlns="dhtsearch.getpredecessor>
- * </host>hohost</host>
- * </query>
- * </iq>
- *
- */
- public void testStabilize6() throws TigaseStringprepException{
- // set preconditions
- ChordNeighborNode otherNode = new ChordNeighborNode("test.info", new ChordKey("test.info"));
- this.nodeUnderTest.setSuccessor(null);
- // test preconditions
- // assertEquals(null, this.nodeUnderTest.getPredecessor().getNodeId()); TODO
- // create Message
- JID from = otherNode.getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:getpredecessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- String[] iqAttrKey = {"from", "to", "id", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "get"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsGet = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsGet);
- // has to result in a getPredecessor result
- Packet actual = this.nodeUnderTest.testPackets.get(0);
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
- assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
- assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
- assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
- assertEquals("nohost", actual.getElemCData("iq/query/host"));
- }
- @Test
- /**
- * __________->successor->__________
- * / \
- * --->[otherNode] [nodeUnderTest]--->
- * / /
- * [newNode]___->successor->_____/ /
- * \ /
- * \____<-predecessor<-______/
- *
- * || || ||
- * \ / \ / \ /
- * \/ \/ \/
- *
- * ________->successor->_______ ________->successor->_______
- * / \/ \
- * --->[otherNode] [newNode] [nodeUnderTest]--->
- * \_______<-predecessor<-______/\_______<-predecessor<-______/
- *
- * key newNode (test.de): 8.174.44.104.87.214.119.6.161.207.126.243.219.228.3.124.37.12.73.62
- * key otherNode (test.gov): 109.49.60.79.34.195.186.64.247.69.125.71.235.179.82.175.114.36.116.11
- * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
- *
- * otherNode has sends this message:
- *
- * <iq from="test.gov" to="mh.local" type="get" id="">
- * <query xmlns="dhtsearch:getpredecessor" />
- * </iq>
- *
- * noderUnderTest then answers this message:
- *
- * <iq from="mh.local" to="test.gov" type="result" id"">
- * <query xmlns="dhtsearch.getpredecessor>
- * </host>test.de</host>
- * </query>
- * </iq>
- *
- *
- */
- public void testStabilize7() throws TigaseStringprepException{
- // set preconditions
- ChordNeighborNode otherNode = new ChordNeighborNode("test.gov", new ChordKey("test.gov"));
- ChordNeighborNode newNode = new ChordNeighborNode("test.de", new ChordKey("test.de"));
- this.nodeUnderTest.setPredecessor(newNode);
- assertEquals(newNode.getNodeId(), this.nodeUnderTest.getPredecessor().getNodeId());
- // create Message
- JID from = otherNode.getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:getpredecessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- String[] iqAttrKey = {"from", "to", "id", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "get"};
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsGet = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsGet);
- Packet actual = this.nodeUnderTest.testPackets.get(0);
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual.getAttribute("from"));
- assertEquals(otherNode.getJID().toString(), actual.getAttribute("to"));
- assertEquals(StanzaType.result.toString(), actual.getAttribute("type"));
- assertEquals("dhtsearch:getpredecessor", actual.getAttribute("iq/query", "xmlns"));
- assertEquals(newNode.getNodeId(), actual.getElemCData("iq/query/host"));
- assertEquals(newNode.getNodeId(), this.nodeUnderTest.getPredecessor().getNodeId());
- }
- @Test
- /**
- * __________->successor->__________
- * / \
- * --->[otherNode1] [otherNode2]--->
- * / /
- * [nodeUnderTest]_->successor->_/ /
- * \ /
- * \____<-predecessor<-______/
- *
- * || || ||
- * \ / \ / \ /
- * \/ \/ \/
- *
- * ________->successor->_______ ________->successor->_______
- * / \/ \
- * --->[otherNode1] [nodeUnderTest] [otherNode2]--->
- * \_______<-predecessor<-______/\_______<-predecessor<-______/
- *
- * key otherNode1 (test.de): 8.174.44.104.87.214.119.6.161.207.126.243.219.228.3.124.37.12.73.62
- * key nodeUnderTest (mh.local): 170.227.18.190.208.51.3.101.248.254.226.235.152.217.21.14.221.82.4.132
- * 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
- *
- * otherNode has sends this message:
- *
- * <iq from="test.de" to="mh.local" type="set" id="">
- * <query xmlns="dhtsearch:notifypredecessor">
- * <host>test.de</host>
- * </iq>
- *
- * nodeUnderTest has to set his predecessor to otherNode1
- *
- *
- */
- public void testStabilize8() throws TigaseStringprepException{
- // // set preconditions
- ChordNeighborNode otherNode1 = new ChordNeighborNode("test.de", new ChordKey("test.de"));
- ChordNeighborNode otherNode2 = new ChordNeighborNode("test.co.uk", new ChordKey("test.co.uk"));
- this.nodeUnderTest.setPredecessor(null);
- this.nodeUnderTest.setSuccessor(otherNode2);
- // test preconditions
- assertTrue(this.nodeUnderTest.getPredecessor() == null);
- assertTrue(this.nodeUnderTest.getSuccessor().getNodeId().equals(otherNode2.getNodeId()));
- //create Message
- JID from = otherNode1.getJID();
- JID to = this.nodeUnderTest.getSelf().getJID();
- String[] queryAttrValue = {"dhtsearch:notifypredecessor"};
- String[] queryAttrKey = {"xmlns"};
- Element queryElement = new Element("query", queryAttrKey, queryAttrValue);
- String[] iqAttrKey = {"from", "to", "id", "type"};
- String[] iqAttrValue = {from.toString(), to.toString(), UUID.randomUUID().toString(), "set"};
- Element hostElement = new Element("host", otherNode1.getNodeId());
- queryElement.addChild(hostElement);
- Element iqElement = new Element("iq", iqAttrKey, iqAttrValue);
- iqElement.addChild(queryElement);
- Packet fsGet = Packet.packetInstance(iqElement);
- this.nodeUnderTest.update(null, fsGet);
- assertEquals(otherNode1.getNodeId(), this.nodeUnderTest.getPredecessor().getNodeId());
- }
- @Test
- /**
- * tests the initial fingertable after fix finger operation
- * without answers
- *
- * preconditions:
- * - number of openOperations: 0
- *
- * postconditions:
- * - number of openOperations: 160
- * - each finger has to be the node itself
- *
- */
- public void testFingerTable0() throws TigaseStringprepException{
- this.nodeUnderTest.fixFingers();
- assertEquals(160, this.nodeUnderTest.getOpenOperations().size());
- FingerTable fingerTabel = this.nodeUnderTest.getFingerTable();
- for (int j = 0; j < 160; j++) {
- assertEquals("mh.local", fingerTabel.getFinger(j).getNode().getNodeId());
- }
- }
- @Test
- /**
- * tests the initial fingertable after fix finger operation
- * with answers
- *
- * preconditions:
- * - number of openOperations: 0
- *
- * postconditions:
- * - number of openOperations: 0
- * - each finger has to be the node itself
- * - message in testPacket has to be the stanza findsuccessor for the last finger
- *
- * last message:
- * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="get">
- * <query xmlns="dhtsearch.findsuccessor">
- * <key>mh.local</key>
- * </query>
- * </iq>
- *
- * answer all messages
- * <iq id="xyz" seq="0" from="dhtsearch@mh.local" to="dhtsearch@mh.local" type="result"
- *
- */
- public void testFingerTable1() throws TigaseStringprepException{
- this.nodeUnderTest.fixFingers();
- assertEquals(160, this.nodeUnderTest.getOpenOperations().size());
- FingerTable fingerTabel = this.nodeUnderTest.getFingerTable();
- for (int j = 0; j < 160; j++) {
- assertEquals("mh.local", fingerTabel.getFinger(j).getNode().getNodeId());
- }
- Packet actual = this.nodeUnderTest.testPackets.lastElement();
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(),actual.getAttribute("from"));
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(),actual.getAttribute("to"));
- assertEquals(StanzaType.get.toString(), actual.getAttribute("type"));
- assertEquals("0", actual.getAttribute("seq"));
- assertEquals("dhtsearch:findsuccessor", actual.getAttribute("iq/query", "xmlns"));
- assertEquals(this.nodeUnderTest.getFingerTable().getFinger(159).getStart().toString(), actual.getElemCData("iq/query/key"));
- assertEquals( 159, this.nodeUnderTest.getOpenOperations().get(UUID.fromString(actual.getAttribute("id"))).getParameter("finger"));
- // check all packets fot the right key
- for (int i = 0; i < this.nodeUnderTest.getFingerTable().size(); i++) {
- assertEquals(this.nodeUnderTest.getFingerTable().getFinger(i).getStart().toString(), this.nodeUnderTest.testPackets.get(i).getElemCData("iq/query/key"));
- }
- // write all the messages to a temporary vector
- Vector<Packet> messages = (Vector<Packet>) this.nodeUnderTest.testPackets.clone();
- this.nodeUnderTest.testPackets.clear();
- // answer all packets
- for (int i = 0; i < messages.size(); i++) {
- this.nodeUnderTest.update(null, messages.get(i));
- }
- // test all the resulting packets
- for (int i = 0; i < this.nodeUnderTest.testPackets.size(); i++) {
- Packet actual1 = this.nodeUnderTest.testPackets.get(i);
- assertEquals(this.nodeUnderTest.getNodeId(), actual1.getElemCData("iq/query/host"));
- assertEquals(StanzaType.result.toString(), actual1.getAttribute("type"));
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual1.getAttribute("to"));
- assertEquals(this.nodeUnderTest.getSelf().getJID().toString(), actual1.getAttribute("from"));
- assertEquals("0", actual1.getAttribute("seq"));
- assertEquals("dhtsearch:findsuccessor", actual1.getAttribute("iq/query", "xmlns"));
- }
- }
- /**
- * method for lookin up keys
- */
- public void keys(){
- System.out.println(new ChordKey("mh.local"));
- System.out.println(new ChordKey("test.de"));
- System.out.println(new ChordKey("test.info"));
- System.out.println(new ChordKey("test.ru"));
- System.out.println(new ChordKey("test.com"));
- System.out.println(new ChordKey("test.org"));
- System.out.println(new ChordKey("test.gov"));
- System.out.println(new ChordKey("test.co.uk"));
- }
- }
Add Comment
Please, Sign In to add comment