@Test
 public void testFindSessionByExternalKey() throws Exception {
   TestSession testSession = createTestSession();
   activeTestSessions.add(testSession);
   assertEquals(
       testSession, activeTestSessions.findSessionByExternalKey(testSession.getExternalKey()));
 }
 @Test
 public void testGetTeraminatedSession() throws Exception {
   TestSession testSession = createTestSession();
   activeTestSessions.add(testSession);
   activeTestSessions.remove(testSession, SessionTerminationReason.ORPHAN);
   assertNull(activeTestSessions.getExistingSession(testSession.getExternalKey()));
 }
 private TestSession createTestSession() {
   final HashMap<String, Object> capabilities = new HashMap<String, Object>();
   final TestSessionTest.TestTimeSource timeSource = new TestSessionTest.TestTimeSource();
   // Luckily we can pass null for TestSlot
   TestSession testSession = new TestSession(null, capabilities, timeSource);
   testSession.setExternalKey(new ExternalSessionKey("w00t!"));
   return testSession;
 }
 @Test
 public void testRemoveWithoutExternalKey() throws Exception {
   TestSession testSession = createTestSession();
   testSession.setExternalKey(null);
   activeTestSessions.add(testSession);
   assertEquals(1, activeTestSessions.unmodifiableSet().size());
   activeTestSessions.remove(testSession, SessionTerminationReason.CLIENT_STOPPED_SESSION);
   assertEquals(0, activeTestSessions.unmodifiableSet().size());
 }
 /** check the normal scenario works */
 @Test(timeout = 1000)
 public void basic() throws InterruptedException {
   // should work
   MockedRequestHandler newSessionRequest = new MockedNewSessionRequestHandler(registry, ff);
   newSessionRequest.process();
   TestSession s = newSessionRequest.getTestSession();
   Assert.assertNotNull(s);
   s.terminate();
   Assert.assertEquals(0, registry.getNewSessionRequests().size());
 }
Ejemplo n.º 6
0
  public TestSession findSessionByInternalKey(String internalKey) {
    if (internalKey == null) {
      return null;
    }

    for (TestSession session : activeTestSessions) {
      if (internalKey.equals(session.getInternalKey())) {
        return session;
      }
    }
    return null;
  }
Ejemplo n.º 7
0
  public TestSession findSessionByExternalKey(ExternalSessionKey externalkey) {
    if (externalkey == null) {
      return null;
    }

    for (TestSession session : activeTestSessions) {
      if (externalkey.equals(session.getExternalKey())) {
        return session;
      }
    }
    return null;
  }
  /**
   * Run the test over device given.
   *
   * @param device the device to run the test.
   */
  public void run(final TestDevice device)
      throws DeviceDisconnectedException, ADBServerNeedRestartException {

    if ((getName() == null) || (getName().length() == 0)) {
      return;
    }

    if (TestSession.exceedsMaxCount()) {
      throw new ADBServerNeedRestartException("Test count reached overflow point");
    } else {
      TestSession.incTestCount();
    }

    mTestStop = false;
    mDevice = device;
    mTimeOutTimer =
        new HostTimer(new TimeOutTask(this), HostConfig.Ints.individualStartTimeoutMs.value());
    mTimeOutTimer.start();
    mProgressObserver = new ProgressObserver();
    mProgressObserver.start();

    setStartTime(System.currentTimeMillis());
    String testFullName = getFullName();
    print(testFullName + "...");

    runImpl();

    synchronized (mTimeOutTimer) {
      if (!mTestStop) {
        try {
          mTimeOutTimer.waitOn();
        } catch (InterruptedException e) {
          Log.d("time out object interrupted");
        }
      }

      mProgressObserver.stop();
      if (mTimeOutTimer.isTimeOut()) {
        return;
      } else {
        // not caused by timer timing out
        // need to cancel timer
        mTimeOutTimer.cancel(false);
      }
    }

    setResult(mResult);
  }
Ejemplo n.º 9
0
  @Test(timeout = 5000)
  public void newSessionSpreadOnAllProxies() {

    // request 5 slots : it should spread the load to 1 FF per proxy.
    for (int i = 0; i < 5; i++) {
      MockedNewSessionRequestHandler req = new MockedNewSessionRequestHandler(registry, ff);
      req.process();
      TestSession session = req.getTestSession();

      Assert.assertNotNull(session);
      Assert.assertEquals(session.getSlot().getProxy().getTotalUsed(), 1);
    }

    // 2 ff per proxy.
    for (int i = 0; i < 5; i++) {
      MockedNewSessionRequestHandler req = new MockedNewSessionRequestHandler(registry, ff);
      req.process();
      TestSession session = req.getTestSession();
      Assert.assertNotNull(session);
      Assert.assertEquals(2, session.getSlot().getProxy().getTotalUsed());
      // and release
      session.terminateSynchronousFOR_TEST_ONLY();
    }

    // at that point, 1 FF per proxy
    for (int i = 0; i < 5; i++) {
      MockedNewSessionRequestHandler req = new MockedNewSessionRequestHandler(registry, ff);
      req.process();
      TestSession session = req.getTestSession();
      Assert.assertNotNull(session);
      Assert.assertEquals(session.getSlot().getProxy().getTotalUsed(), 2);
    }
  }
Ejemplo n.º 10
0
  private void updateReason(TestSession o, SessionTerminationReason reason) {
    if (o.getExternalKey() == null) {
      if (SessionTerminationReason.CREATIONFAILED != reason) { // Should not happen. Yeah.
        log.info(
            "Removed a session that had not yet assigned an external key "
                + o.getInternalKey()
                + ", indicates failure in session creation "
                + reason);
      }
      return;
    }

    terminatedSessions.add(o.getExternalKey());
    reasons.put(o.getExternalKey(), reason);
    if (reasons.size() > 1000) {
      ExternalSessionKey remove = terminatedSessions.remove();
      reasons.remove(remove);
    }
  }
Ejemplo n.º 11
0
  @Test
  public void testSubCategorySerializer() {
    TestSession session = new TestSession();
    session.setAuthenticated(true);
    session.setId("abcabvabv");
    session.setLastAccessed(System.currentTimeMillis());

    TestUser user = new TestUser();
    user.setRole("admin");
    user.setId("*****@*****.**");
    user.setPassword("123abc124abd");

    session.setUser(user);

    TestUser user2 = new TestUser();
    user2.setRole("role2");
    user2.setId("*****@*****.**");
    user2.setPassword("987987");

    TestUser user3 = new TestUser();
    user3.setRole("role4");
    user3.setId("*****@*****.**");
    user3.setPassword("777888222a");

    session.getUsers().add(user2);
    session.getUsers().add(user3);

    System.out.println(new Gson().toJson(session));

    SubCategoryData sd = SubCategoryUtil.convertObjectToSubCateogory(session);

    System.out.println(new Gson().toJson(sd));
  }
Ejemplo n.º 12
0
 @Override
 public String toString() {
   return currentSession == null ? "no session" : currentSession.toString();
 }
Ejemplo n.º 13
0
 String getInternalKey() {
   return currentSession == null ? null : currentSession.getInternalKey();
 }