예제 #1
0
  @Test
  public void testUserRegistry() throws CryptoException, L2pSecurityException, AgentException {
    UserAgent a = UserAgent.createUserAgent("a");
    UserAgent b = UserAgent.createUserAgent("b");

    a.unlockPrivateKey("a");
    b.unlockPrivateKey("b");

    a.setLoginName("alpha");
    b.setLoginName("beta");

    LocalNode testee = LocalNode.launchNode();
    testee.storeAgent(a);
    testee.storeAgent(b);

    assertEquals(a.getId(), testee.getAgentIdForLogin("alpha"));
    assertEquals(b.getId(), testee.getAgentIdForLogin("beta"));

    try {
      testee.getAgentIdForLogin("bla");
      fail("AgentNotKnownException expected");
    } catch (AgentNotKnownException e) {
      // corrects
    }
  }
예제 #2
0
  @Test
  public void testPending()
      throws L2pSecurityException, EncodingFailedException, SerializationException,
          InterruptedException, AgentException {
    adam.unlockPrivateKey("adamspass");
    eve.unlockPrivateKey("evespass");

    LocalNode testee = LocalNode.launchAgent(adam);

    MessageResultListener l =
        new MessageResultListener(4000) {
          @Override
          public void notifySuccess() {
            LocalNodeTest.testVariable = true;
          }
        };

    Message m = new Message(adam, eve, new PingPongContent());
    testee.sendMessage(m, l);

    Thread.sleep(2000);

    assertFalse(testVariable);
    assertFalse(l.isSuccess());
    assertFalse(l.isFinished());

    // launch another node hosting eve
    LocalNode.launchAgent(eve);
    Thread.sleep(LocalNode.getMaxMessageWait() + 3000);

    assertTrue(l.isSuccess());
    assertTrue(l.isFinished());
    assertTrue(testVariable);
  }
예제 #3
0
  @Test
  public void testSimpleInvokation()
      throws L2pSecurityException, CryptoException, AgentAlreadyRegisteredException, AgentException,
          SecurityException, IllegalArgumentException, AgentNotKnownException,
          NoSuchMethodException, IllegalAccessException, InvocationTargetException,
          InterruptedException {
    String serviceClass = "i5.las2peer.api.TestService";
    ServiceAgent testService = ServiceAgent.generateNewAgent(serviceClass, "a passphrase");
    testService.unlockPrivateKey("a passphrase");

    LocalNode testee = LocalNode.launchNode();

    eve.unlockPrivateKey("evespass");
    testee.storeAgent(eve);
    eve.lockPrivateKey();

    testee.storeAgent(testService);
    testee.registerReceiver(testService);

    Serializable result =
        testee.invokeLocally(
            eve.getId(), serviceClass, "inc", new Serializable[] {new Integer(10)});

    assertEquals(12, result);
  }
예제 #4
0
  @Test
  public void testTwoNodes()
      throws L2pSecurityException, EncodingFailedException, SerializationException,
          InterruptedException, AgentException {
    adam.unlockPrivateKey("adamspass");
    eve.unlockPrivateKey("evespass");

    // launch to nodes with one agent each
    LocalNode testee1 = LocalNode.launchAgent(adam);
    LocalNode.launchAgent(eve);

    assertTrue(LocalNode.findAllNodesWithAgent(adam.getId()).length > 0);
    assertTrue(LocalNode.findAllNodesWithAgent(eve.getId()).length > 0);

    MessageResultListener l = new MessageResultListener(10000);
    Message m = new Message(adam, eve, new PingPongContent());

    testee1.sendMessage(m, l);

    l.waitForAllAnswers();

    assertEquals(1, l.getNumberOfExpectedResults());
    assertTrue(l.isFinished());
    assertTrue(l.isSuccess());
  }
예제 #5
0
  @Test
  public void test()
      throws AgentAlreadyRegisteredException, EncodingFailedException, L2pSecurityException,
          SerializationException, InterruptedException, AgentException, AgentNotKnownException {
    System.out.println("start: " + new Date());

    LocalNode testee = LocalNode.launchNode();

    try {
      testee.registerReceiver(eve);
      fail("L2pSecurityException expected");
    } catch (L2pSecurityException e) {
    }

    eve.unlockPrivateKey("evespass");
    adam.unlockPrivateKey("adamspass");

    testee.registerReceiver(eve);
    testee.registerReceiver(adam);

    assertFalse(eve.isLocked());
    assertFalse(adam.isLocked());

    System.out.println("check1: " + new Date());

    testVariable = false;
    MessageResultListener listener =
        new MessageResultListener(10000) {
          public void notifySuccess() {
            LocalNodeTest.testVariable = true;
          }
        };

    PingPongContent c = new PingPongContent();
    Message m = new Message(adam, eve, c);

    testee.sendMessage(m, listener);

    listener.waitForAllAnswers();

    assertFalse(listener.isTimedOut());
    assertFalse(listener.hasException());
    assertTrue(listener.isSuccess());
    assertTrue(listener.isFinished());

    Message answer = listener.getResults()[0];
    answer.open(adam, testee);
    assertTrue(c.getTimestamp() < ((PingPongContent) answer.getContent()).getTimestamp());
    assertTrue(testVariable);
  }
  /**
   * Called before the tests start.
   *
   * <p>Sets up the node and initializes connector and users that can be used throughout the tests.
   *
   * @throws Exception
   */
  @BeforeClass
  public static void startServer() throws Exception {

    // start node
    node = LocalNode.newNode();
    testAgent = MockAgentFactory.getAdam();
    testAgent.unlockPrivateKey(testPass); // agent must be unlocked in order to be stored
    node.storeAgent(testAgent);
    node.launch();

    ServiceAgent testService = ServiceAgent.createServiceAgent(testTemplateService, "a pass");
    testService.unlockPrivateKey("a pass");

    node.registerReceiver(testService);

    // start connector
    logStream = new ByteArrayOutputStream();

    connector = new WebConnector(true, HTTP_PORT, false, 1000);
    connector.setLogStream(new PrintStream(logStream));
    connector.start(node);
    Thread.sleep(1000); // wait a second for the connector to become ready
    testAgent = MockAgentFactory.getAdam();

    connector.updateServiceList();
    // avoid timing errors: wait for the repository manager to get all services before continuing
    try {
      System.out.println("waiting..");
      Thread.sleep(10000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
예제 #7
0
  @Test
  public void testTimeout()
      throws EncodingFailedException, L2pSecurityException, SerializationException,
          InterruptedException, AgentException {
    adam.unlockPrivateKey("adamspass");

    LocalNode testee1 = LocalNode.launchAgent(adam);
    MessageResultListener l =
        new MessageResultListener(2000) {
          public void notifyTimeout() {
            LocalNodeTest.testVariable = true;
          }
        };
    Message m = new Message(adam, eve, new PingPongContent(), 1000);

    LocalNode.setPendingTimeOut(1000);

    testee1.sendMessage(m, l);

    Thread.sleep(30000);

    assertFalse(l.isSuccess());
    assertTrue(l.isTimedOut());
    assertEquals(0, l.getResults().length);
    assertTrue(testVariable);
  }
  @Test
  public void getNames() {

    Client c = new Client(HTTP_ADDRESS, HTTP_PORT, adam.getLoginName(), adamsPass);

    try {
      // Login
      c.connect();

      Object result = c.invoke(testServiceClass.getName(), "getMeasureNames", true);
      assertTrue(result instanceof String[]);
      String[] resultArray = (String[]) result;
      for (String measureName : resultArray)
        System.out.println("Result of asking for all measures: " + measureName);

      result = c.invoke(testServiceClass.getName(), "getNodes");
      assertTrue(result instanceof String[]);
      resultArray = (String[]) result;
      for (String node : resultArray) System.out.println("Result of asking for all nodes: " + node);

      result = c.invoke(testServiceClass.getName(), "getServices");
      assertTrue(result instanceof String[]);
      resultArray = (String[]) result;
      for (String service : resultArray)
        System.out.println("Result of asking for all monitored service names: " + service);
      if (resultArray.length != 0) {
        String serviceName = resultArray[0];
        System.out.println("Calling getModels with service: " + serviceName);
        result = c.invoke(testServiceClass.getName(), "getModels", serviceName, true);
        assertTrue(result instanceof String[]);
        resultArray = (String[]) result;
        for (String service : resultArray)
          System.out.println("Result of asking for all models: " + service);
      } else System.out.println("Result of asking for all monitored service names: none!");

    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception: " + e);
    }

    try {

      // Logout
      c.disconnect();

    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception: " + e);
    }
  }
예제 #9
0
  @Test
  public void testUserRegDistribution()
      throws L2pSecurityException, AgentException, CryptoException, ArtifactNotFoundException {
    LocalNode testee1 = LocalNode.launchNode();

    long id = Envelope.getClassEnvelopeId(UserAgentList.class, "mainlist");

    for (int i = 0; i < 11; i++) {
      UserAgent a = UserAgent.createUserAgent("pass" + i);
      a.unlockPrivateKey("pass" + i);
      a.setLoginName("login_" + i);
      testee1.storeAgent(a);
    }

    // check, that the user list is stored
    testee1.fetchArtifact(id);

    LocalNode testee2 = LocalNode.launchNode();

    // check, that the user list is stored
    testee2.fetchArtifact(id);

    testee2.getAgentIdForLogin("login_2");
  }
  @Test
  public void getMeasuresAndModels() {

    Client c = new Client(HTTP_ADDRESS, HTTP_PORT, adam.getLoginName(), adamsPass);

    try {
      // Login
      c.connect();
      Object result = c.invoke(testServiceClass.getName(), "getNodes");
      String[] resultArray = (String[]) result;
      if (resultArray.length != 0) {
        String knownNode = ((String[]) result)[0];
        System.out.println("Calling Node Success Model with node " + knownNode);

        result =
            c.invoke(
                testServiceClass.getName(), "visualizeNodeSuccessModel", knownNode, true, true);
        assertTrue(result instanceof String);
        System.out.println("Visualizing Node Success Model Result:\n" + result);
      } else
        System.out.println("No monitored nodes, no node success model visualization possible!");

      result =
          c.invoke(
              testServiceClass.getName(),
              "visualizeServiceSuccessModel",
              "Chat Service Success Model",
              true,
              true);
      assertTrue(result instanceof String);
      System.out.println("Visualizing Chat Service Success Model Result:\n" + result);

    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception: " + e);
    }

    try {

      // Logout
      c.disconnect();

    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception: " + e);
    }
  }
예제 #11
0
  @Test
  public void testStartupAgents() throws L2pSecurityException, AgentException {

    LocalNode testee = LocalNode.newNode();
    testee.storeAgent(adam);

    testee.launch();

    try {
      testee.storeAgent(abel);
      fail("L2pSecurityException expected");
    } catch (L2pSecurityException e) {
      // ok
    }

    abel.unlockPrivateKey("abelspass");
    testee.storeAgent(abel);
  }
 /** Test for the getGraphList method. */
 @Test
 public void testgetGraphList() {
   MiniClient c = new MiniClient();
   c.setAddressPort(HTTP_ADDRESS, HTTP_PORT);
   try {
     c.setLogin(Long.toString(testAgent.getId()), testPass);
     @SuppressWarnings("unchecked")
     ClientResponse result =
         c.sendRequest(
             "GET",
             mainPath + "/",
             "",
             MediaType.TEXT_PLAIN,
             MediaType.APPLICATION_JSON,
             new Pair[] {});
     assertTrue(true); // change here
     System.out.println("Result of 'testgetGraphList': " + result.getResponse().trim());
   } catch (Exception e) {
     e.printStackTrace();
     fail("Exception: " + e);
   }
 }
  @Before
  public void startServer() throws Exception {
    // start Node
    node = LocalNode.newNode();

    adam = MockAgentFactory.getAdam();
    adam.unlockPrivateKey(adamsPass);
    node.storeAgent(adam);

    node.launch();

    ServiceAgent testService = ServiceAgent.createServiceAgent(testServiceClass, "a pass");
    testService.unlockPrivateKey("a pass");

    node.registerReceiver(testService);

    // start connector
    logStream = new ByteArrayOutputStream();
    connector = new HttpConnector();
    connector.setSocketTimeout(10000);
    connector.setLogStream(new PrintStream(logStream));
    connector.start(node);
  }
예제 #14
0
  @Test
  public void testBroadcast()
      throws EncodingFailedException, L2pSecurityException, SerializationException,
          InterruptedException, AgentException, AgentNotKnownException {
    adam.unlockPrivateKey("adamspass");
    eve.unlockPrivateKey("evespass");

    // launch three nodes with one agent each
    LocalNode testee1 = LocalNode.launchAgent(adam);
    LocalNode hosting1 = LocalNode.launchAgent(eve);
    assertEquals(1, LocalNode.findAllNodesWithAgent(eve.getId()).length);

    LocalNode hosting2 = LocalNode.launchAgent(eve);

    assertTrue(hosting1.hasLocalAgent(eve));
    assertTrue(hosting2.hasLocalAgent(eve));

    assertNotSame(hosting1.getAgent(eve.getId()), hosting2.getAgent(eve.getId()));

    assertEquals(2, LocalNode.findAllNodesWithAgent(eve.getId()).length);

    MessageResultListener l =
        new MessageResultListener(10000) {
          public void notifySuccess() {
            synchronized (this) {
              System.out.println("result retrieved");
              LocalNodeTest.counter++;
            }
          }
        };
    // l.addRecipient();
    assertEquals(1, l.getNumberOfExpectedResults());

    Message m = new Message(adam, eve, new PingPongContent());
    testee1.sendMessage(m, l, Node.SendMode.BROADCAST);
    assertEquals(2, l.getNumberOfExpectedResults());

    l.waitForAllAnswers();

    assertEquals(2, l.getNumberOfResults());
    assertEquals(counter, 2);
    assertTrue(l.isSuccess());
    assertTrue(l.isFinished());
  }
예제 #15
0
  @Test
  public void testRegisteringAgents()
      throws L2pSecurityException, MalformedXMLException, IOException,
          AgentAlreadyRegisteredException, AgentNotKnownException, AgentException {
    adam.unlockPrivateKey("adamspass");
    // abel.unlockPrivateKey ( "abelspass");

    LocalNode testee = LocalNode.launchAgent(adam);

    // testee.storeAgent(abel);

    try {
      testee.storeAgent(abel);
      fail("L2sSecurityAxception expected");
    } catch (L2pSecurityException e) {
    }

    try {
      testee.storeAgent(adam);
      fail("AgentAlreadyRegistered exception expected");
    } catch (AgentAlreadyRegisteredException e) {
    }

    abel.unlockPrivateKey("abelspass");
    testee.storeAgent(abel);

    LocalNode testee2 = LocalNode.launchNode();

    UserAgent retrieve = (UserAgent) testee2.getAgent(abel.getId());
    assertTrue(retrieve.isLocked());

    try {
      testee2.updateAgent(retrieve);
      fail("SecurtityException expected");
    } catch (L2pSecurityException e) {
    }

    retrieve.unlockPrivateKey("abelspass");
    testee2.updateAgent(retrieve);
  }