@Test
 public void get_A$String() throws Exception {
   MemcachedSessionStore store = new MemcachedSessionStore(getMemcached());
   // given
   String key = "MemcachedSessionStoreTest#get_A$String_" + System.currentTimeMillis();
   String value = "cached" + System.currentTimeMillis();
   store.set(key, 60, value);
   // when
   String actual = store.get(key);
   // then
   assertThat(actual, is(equalTo(value)));
 }
  // --- NBHMLFeeder ---
  // Class to be called from another thread, to get concurrent installs into
  // the table.
  private static class NBHMLFeeder implements Callable<Object> {
    private static final Random _rand = new Random(System.currentTimeMillis());
    private final NonBlockingIdentityHashMap<Long, TestKey> _map;
    private final int _count;
    private final CyclicBarrier _barrier;
    private final long _offset;

    public NBHMLFeeder(
        final NonBlockingIdentityHashMap<Long, TestKey> map,
        final int count,
        final CyclicBarrier barrier,
        final long offset) {
      _map = map;
      _count = count;
      _barrier = barrier;
      _offset = offset;
    }

    public Object call() throws Exception {
      _barrier.await(); // barrier, to force racing start
      for (long j = 0; j < _count; j++)
        _map.put(
            j + _offset,
            new TestKey(_rand.nextLong(), _rand.nextInt(), (short) _rand.nextInt(Short.MAX_VALUE)));
      return null;
    }
  }
 @Test
 public void remove_A$String() throws Exception {
   MemcachedSessionStore store = new MemcachedSessionStore(getMemcached());
   // given
   String key = "MemcachedSessionStoreTest#remove_A$String_" + System.currentTimeMillis();
   // when
   store.set(key, 60, "aaa");
   store.remove(key);
   String actual = store.get(key);
   // then
   assertThat(actual, is(nullValue()));
 }
  @Test
  public void testLongProfiling() throws Exception {

    Logger logger = Logger.getLogger(getClass());
    MDC.put(GelfUtil.MDC_REQUEST_START_MS, "" + (System.currentTimeMillis() - 2000));

    logger.info(LOG_MESSAGE);
    assertEquals(1, GelfTestSender.getMessages().size());

    GelfMessage gelfMessage = GelfTestSender.getMessages().get(0);

    assertNotNull(gelfMessage.getField(GelfUtil.MDC_REQUEST_DURATION));
    assertNotNull(gelfMessage.getField(GelfUtil.MDC_REQUEST_END));
  }
 @Test
 public void set_A$String$int$Object_Expire() throws Exception {
   MemcachedSessionStore store = new MemcachedSessionStore(getMemcached());
   // given
   String key = "MemcachedSessionStoreTest#set_A$String$int$Object_" + System.currentTimeMillis();
   int expire = 2;
   String value = "aaa";
   // when
   store.set(key, expire, value);
   Thread.sleep(3000L);
   String actual = store.get(key);
   // then
   assertThat(actual, is(nullValue()));
 }
  @Test
  public void retrieveCalendar() throws Exception {
    final String calendarName = "weekdayCalendar";
    Calendar calendar = getCalendar();
    jobStore.storeCalendar(calendarName, calendar, false, false);

    Calendar retrievedCalendar = jobStore.retrieveCalendar(calendarName);

    assertEquals(calendar.getClass(), retrievedCalendar.getClass());
    assertEquals(calendar.getDescription(), retrievedCalendar.getDescription());
    long currentTime = System.currentTimeMillis();
    assertEquals(
        calendar.getNextIncludedTime(currentTime),
        retrievedCalendar.getNextIncludedTime(currentTime));
  }
  @Before
  public void setup() throws IOException {
    CouchConfig config = super.getCouchConfig(CLOUDANT_TEST_DB_NAME + System.currentTimeMillis());
    remoteDb =
        new CouchClientWrapper(
            config.getRootUri(), config.getRequestInterceptors(), config.getResponseInterceptors());
    bodyOne =
        DocumentBodyFactory.create(
            FileUtils.readFileToByteArray(TestUtils.loadFixture(documentOneFile)));
    bodyTwo =
        DocumentBodyFactory.create(
            FileUtils.readFileToByteArray(TestUtils.loadFixture(documentTwoFile)));

    CouchClientWrapperDbUtils.deleteDbQuietly(remoteDb);
    remoteDb.createDatabase();
  }
Example #8
0
  @Test
  public void test1create() throws InterruptedException {
    long now = System.currentTimeMillis();

    Thread.sleep(20);

    String token = store.newToken("*****@*****.**", "domain.com");

    assertThat(token, is(notNullValue()));
    assertThat(token.length(), is(not(0)));
    assertThat(store.getSessions().size(), is(1));

    Session s = store.getSessions().get(0);

    assertThat(s.getId(), is(notNullValue()));
    assertThat(s.getDomain(), is("domain.com"));
    assertThat(s.getToken(), is(token));
    assertThat(s.getUser(), is("*****@*****.**"));
    assertThat(s.getSessionStart(), is(greaterThan(now)));
    assertThat(s.getSessionExpiration(), is(greaterThan(s.getSessionStart())));
  }
Example #9
0
  public IsisSessionDefault(
      final IsisSessionFactory sessionFactory,
      final AuthenticationSession authenticationSession,
      final PersistenceSession persistenceSession) {

    // global context
    ensureThatArg(sessionFactory, is(not(nullValue())), "execution context factory is required");

    // session
    ensureThatArg(
        authenticationSession, is(not(nullValue())), "authentication session is required");
    ensureThatArg(persistenceSession, is(not(nullValue())), "persistence session is required");

    this.isisSessionFactory = sessionFactory;

    this.authenticationSession = authenticationSession;
    this.persistenceSession = persistenceSession;

    setSessionOpenTime(System.currentTimeMillis());

    this.id = nextId++;
  }