io.vertx.ext.web.sstore.SessionStore Java Examples

The following examples show how to use io.vertx.ext.web.sstore.SessionStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test
public void storeShouldRemoveExpiredSessionFromLocalAndRemote(TestContext context) {
    Vertx vertx = rule.vertx();
    Async async = context.async();
    SessionStore sessionStore = NearCacheSessionStore.create(vertx);
    Session session = sessionStore.createSession(3000);
    sessionStore.put(session, context.asyncAssertSuccess());


    vertx.setTimer(5000, unused -> {
        sessionStore.get("XY", context.asyncAssertSuccess(u -> {
            doWithRemoteSession(context, session, context.asyncAssertSuccess(s ->
                context.assertNull(s, "Remote session should not be present")
            ));
            doWithLocalSession(context, session, context.asyncAssertSuccess(s ->
                context.assertNull(s, "Local session should not be present")
            ));
        }));
        async.complete();
    });
}
 
Example #2
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test
public void storeShouldRemoveExpiredSessionFromLocalAndRemote(TestContext context) {
    Vertx vertx = rule.vertx();
    Async async = context.async();
    SessionStore sessionStore = NearCacheSessionStore.create(vertx);
    Session session = sessionStore.createSession(3000);
    sessionStore.put(session, context.asyncAssertSuccess());


    vertx.setTimer(5000, unused -> {
        sessionStore.get("XY", context.asyncAssertSuccess(u -> {
            doWithRemoteSession(context, session, context.asyncAssertSuccess(s ->
                context.assertNull(s, "Remote session should not be present")
            ));
            doWithLocalSession(context, session, context.asyncAssertSuccess(s ->
                context.assertNull(s, "Local session should not be present")
            ));
        }));
        async.complete();
    });
}
 
Example #3
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test(timeout = 5000)
public void clearShouldEmptyLocalAndRemoteSession(TestContext context) {
    Vertx vertx = rule.vertx();
    SessionStore sessionStore = NearCacheSessionStore.create(vertx);
    Session session = sessionStore.createSession(DEFAULT_TIMEOUT);
    TestObject testObject = new TestObject("TestObject");
    session.put("TEST_KEY", testObject);

    sessionStore.clear(context.asyncAssertSuccess(u -> {
        context.assertTrue(localMap.isEmpty(), "Local map should be empty");
        remoteMap.size(context.asyncAssertSuccess(size ->
            context.assertTrue(size == 0, "Remote map should be empty")
        ));

    }));
}
 
Example #4
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test(timeout = 5000)
public void getShouldReturnRemoteSessionIfLocalIsMissingPresent(TestContext context) {
    Vertx vertx = rule.vertx();
    TestObject testObject = new TestObject("TestObject");
    ExtendedSession session = createSession(vertx);
    String testObjKey = "testObjKey";
    session.put(testObjKey, testObject);
    remoteMap.put(session.id(), session, context.asyncAssertSuccess());

    SessionStore sessionStore = NearCacheSessionStore.create(vertx);

    sessionStore.get(session.id(), context.asyncAssertSuccess(s -> {
        assertSessionProperties(session, s);
        assertThat(s.<TestObject>get(testObjKey)).isNotSameAs(testObject).isEqualTo(testObject);
    }));
}
 
Example #5
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test(timeout = 5000)
public void getShouldReturnLocalSessionIfPresent(TestContext context) {
    Vertx vertx = rule.vertx();
    TestObject testObject = new TestObject("TestObject");
    ExtendedSession session = createSession(vertx);
    String testObjKey = "testObjKey";
    session.put(testObjKey, testObject);
    localMap.put(session.id(), session);

    SessionStore sessionStore = NearCacheSessionStore.create(vertx);

    sessionStore.get(session.id(), context.asyncAssertSuccess(s -> {
        assertSessionProperties(session, s);
        assertThat(s.<TestObject>get(testObjKey)).isSameAs(testObject);
    }));
}
 
Example #6
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test(timeout = 3000)
public void consecutiveGetAndPutShouldBeConsistent(TestContext context) {
    Vertx vertx = rule.vertx();

    TestObject testObject = new TestObject("TestObject");
    ExtendedSession session = createSession(vertx);
    String testObjKey = "testObjKey";
    session.put(testObjKey, testObject);

    SessionStore sessionStore = NearCacheSessionStore.create(vertx);
    sessionStore.put(session, context.asyncAssertSuccess(x -> {
        sessionStore.get(session.id(), context.asyncAssertSuccess(freshSession -> {
            sessionStore.put(freshSession, context.asyncAssertSuccess());
        }));
    }));


}
 
Example #7
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test(timeout = 3000)
public void putShouldUpdateRemoteSession(TestContext context) {
    Vertx vertx = rule.vertx();

    TestObject testObject = new TestObject("TestObject");
    ExtendedSession session = createSession(vertx);
    String testObjKey = "testObjKey";
    session.put(testObjKey, testObject);

    SessionStore sessionStore = NearCacheSessionStore.create(vertx);
    sessionStore.put(session, context.asyncAssertSuccess(b -> {
        doWithRemoteSession(context, session, context.asyncAssertSuccess(s ->
            context.verify(unused -> assertSessionProperties(session, s))
        ));
        doWithLocalSession(context, session, context.asyncAssertSuccess(s ->
            context.verify(unused -> {
                assertSessionProperties(session, s);

            })
        ));
    }));
}
 
Example #8
Source File: WebExamples.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
public void example31(Vertx vertx) {

    // Create a local session store using defaults
    SessionStore store1 = LocalSessionStore.create(vertx);

    // Create a local session store specifying the local shared map name to use
    // This might be useful if you have more than one application in the same
    // Vert.x instance and want to use different maps for different applications
    SessionStore store2 = LocalSessionStore.create(
      vertx,
      "myapp3.sessionmap");

    // Create a local session store specifying the local shared map name to use and
    // setting the reaper interval for expired sessions to 10 seconds
    SessionStore store3 = LocalSessionStore.create(
      vertx,
      "myapp3.sessionmap",
      10000);

  }
 
Example #9
Source File: ExtendedSessionUT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test
public void extendeSessionShouldBeClusterSerializable() throws InterruptedException {
    Vertx vertx = Vertx.vertx();
    SharedDataSessionImpl delegate = new SharedDataSessionImpl(new PRNG(vertx), 3000, SessionStore.DEFAULT_SESSIONID_LENGTH);
    ExtendedSession extendedSession = ExtendedSession.adapt(delegate);
    assertThat(extendedSession).isInstanceOf(ClusterSerializable.class);
    long createdAt = extendedSession.createdAt();
    extendedSession.put("key1", "value");
    extendedSession.put("key2", 20);
    Thread.sleep(300);

    Buffer buffer = Buffer.buffer();
    ((ClusterSerializable) extendedSession).writeToBuffer(buffer);
    assertThat(buffer.length() > 0);

    ExtendedSession fromBuffer = ExtendedSession.adapt(
        new SharedDataSessionImpl(new PRNG(vertx), 0, SessionStore.DEFAULT_SESSIONID_LENGTH)
    );
    ((ClusterSerializable) fromBuffer).readFromBuffer(0, buffer);
    assertThat(fromBuffer.createdAt()).isEqualTo(createdAt);
    assertThat(fromBuffer.id()).isEqualTo(delegate.id());
    assertThat(fromBuffer.timeout()).isEqualTo(delegate.timeout());
    assertThat(fromBuffer.data()).isEqualTo(delegate.data());

}
 
Example #10
Source File: WebExamples.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
public void example32() {

    // a clustered Vert.x
    Vertx.clusteredVertx(new VertxOptions(), res -> {

      Vertx vertx = res.result();

      // Create a clustered session store using defaults
      SessionStore store1 = ClusteredSessionStore.create(vertx);

      // Create a clustered session store specifying the distributed map name to use
      // This might be useful if you have more than one application in the cluster
      // and want to use different maps for different applications
      SessionStore store2 = ClusteredSessionStore.create(
        vertx,
        "myclusteredapp3.sessionmap");
    });

  }
 
Example #11
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test(timeout = 5000)
public void clearShouldEmptyLocalAndRemoteSession(TestContext context) {
    Vertx vertx = rule.vertx();
    SessionStore sessionStore = NearCacheSessionStore.create(vertx);
    Session session = sessionStore.createSession(DEFAULT_TIMEOUT);
    TestObject testObject = new TestObject("TestObject");
    session.put("TEST_KEY", testObject);

    sessionStore.clear(context.asyncAssertSuccess(u -> {
        context.assertTrue(localMap.isEmpty(), "Local map should be empty");
        remoteMap.size(context.asyncAssertSuccess(size ->
            context.assertTrue(size == 0, "Remote map should be empty")
        ));

    }));
}
 
Example #12
Source File: RedirectAuthHandlerTest.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
private void doLoginCommon(Handler<RoutingContext> handler) throws Exception {
  router.route().handler(BodyHandler.create());
  SessionStore store = LocalSessionStore.create(vertx);
  router.route().handler(SessionHandler.create(store));
  AuthenticationHandler authHandler = RedirectAuthHandler.create(authProvider);
  router.route("/protected/*").handler(authHandler);
  router.route("/protected/somepage").handler(handler);
  String loginHTML = createloginHTML();
  router.route("/loginpage").handler(rc -> rc.response().putHeader("content-type", "text/html").end(loginHTML));
  if (formLoginHandler == null) {
    formLoginHandler = FormLoginHandler.create(authProvider);
  }
  router.route("/login").handler(formLoginHandler);
  testRequest(HttpMethod.GET, "/protected/somepage", null, resp -> {
    String location = resp.headers().get("location");
    assertNotNull(location);
    assertEquals("/loginpage", location);
    String setCookie = resp.headers().get("set-cookie");
    assertNotNull(setCookie);
    sessionCookie.set(setCookie);
  }, 302, "Found", null);
  testRequest(HttpMethod.GET, "/loginpage", req -> req.putHeader("cookie", sessionCookie.get()), resp -> {
  }, 200, "OK", loginHTML);
}
 
Example #13
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test(timeout = 5000)
public void getShouldReturnRemoteSessionIfLocalIsMissingPresent(TestContext context) {
    Vertx vertx = rule.vertx();
    TestObject testObject = new TestObject("TestObject");
    ExtendedSession session = createSession(vertx);
    String testObjKey = "testObjKey";
    session.put(testObjKey, testObject);
    remoteMap.put(session.id(), session, context.asyncAssertSuccess());

    SessionStore sessionStore = NearCacheSessionStore.create(vertx);

    sessionStore.get(session.id(), context.asyncAssertSuccess(s -> {
        assertSessionProperties(session, s);
        assertThat(s.<TestObject>get(testObjKey)).isNotSameAs(testObject).isEqualTo(testObject);
    }));
}
 
Example #14
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test(timeout = 5000)
public void getShouldReturnLocalSessionIfPresent(TestContext context) {
    Vertx vertx = rule.vertx();
    TestObject testObject = new TestObject("TestObject");
    ExtendedSession session = createSession(vertx);
    String testObjKey = "testObjKey";
    session.put(testObjKey, testObject);
    localMap.put(session.id(), session);

    SessionStore sessionStore = NearCacheSessionStore.create(vertx);

    sessionStore.get(session.id(), context.asyncAssertSuccess(s -> {
        assertSessionProperties(session, s);
        assertThat(s.<TestObject>get(testObjKey)).isSameAs(testObject);
    }));
}
 
Example #15
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test(timeout = 3000)
public void consecutiveGetAndPutShouldBeConsistent(TestContext context) {
    Vertx vertx = rule.vertx();

    TestObject testObject = new TestObject("TestObject");
    ExtendedSession session = createSession(vertx);
    String testObjKey = "testObjKey";
    session.put(testObjKey, testObject);

    SessionStore sessionStore = NearCacheSessionStore.create(vertx);
    sessionStore.put(session, context.asyncAssertSuccess(x -> {
        sessionStore.get(session.id(), context.asyncAssertSuccess(freshSession -> {
            sessionStore.put(freshSession, context.asyncAssertSuccess());
        }));
    }));


}
 
Example #16
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test(timeout = 3000)
public void putShouldUpdateRemoteSession(TestContext context) {
    Vertx vertx = rule.vertx();

    TestObject testObject = new TestObject("TestObject");
    ExtendedSession session = createSession(vertx);
    String testObjKey = "testObjKey";
    session.put(testObjKey, testObject);

    SessionStore sessionStore = NearCacheSessionStore.create(vertx);
    sessionStore.put(session, context.asyncAssertSuccess(b -> {
        doWithRemoteSession(context, session, context.asyncAssertSuccess(s ->
            context.verify(unused -> assertSessionProperties(session, s))
        ));
        doWithLocalSession(context, session, context.asyncAssertSuccess(s ->
            context.verify(unused -> {
                assertSessionProperties(session, s);

            })
        ));
    }));
}
 
Example #17
Source File: ExtendedSessionUT.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Test
public void extendeSessionShouldBeClusterSerializable() throws InterruptedException {
    Vertx vertx = Vertx.vertx();
    SharedDataSessionImpl delegate = new SharedDataSessionImpl(new PRNG(vertx), 3000, SessionStore.DEFAULT_SESSIONID_LENGTH);
    ExtendedSession extendedSession = ExtendedSession.adapt(delegate);
    assertThat(extendedSession).isInstanceOf(ClusterSerializable.class);
    long createdAt = extendedSession.createdAt();
    extendedSession.put("key1", "value");
    extendedSession.put("key2", 20);
    Thread.sleep(300);

    Buffer buffer = Buffer.buffer();
    ((ClusterSerializable) extendedSession).writeToBuffer(buffer);
    assertThat(buffer.length() > 0);

    ExtendedSession fromBuffer = ExtendedSession.adapt(
        new SharedDataSessionImpl(new PRNG(vertx), 0, SessionStore.DEFAULT_SESSIONID_LENGTH)
    );
    ((ClusterSerializable) fromBuffer).readFromBuffer(0, buffer);
    assertThat(fromBuffer.createdAt()).isEqualTo(createdAt);
    assertThat(fromBuffer.id()).isEqualTo(delegate.id());
    assertThat(fromBuffer.timeout()).isEqualTo(delegate.timeout());
    assertThat(fromBuffer.data()).isEqualTo(delegate.data());

}
 
Example #18
Source File: LocalSessionStoreImpl.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Override
public SessionStore init(Vertx vertx, JsonObject options) {
  // initialize a secure random
  this.random = VertxContextPRNG.current(vertx);
  this.vertx = vertx;
  this.reaperInterval = options.getLong("reaperInterval", DEFAULT_REAPER_INTERVAL);
  localMap = vertx.sharedData().getLocalMap(options.getString("mapName", DEFAULT_SESSION_MAP_NAME));
  setTimer();

  return this;
}
 
Example #19
Source File: ClusteredSessionStoreImpl.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Override
public SessionStore init(Vertx vertx, JsonObject options) {
  this.vertx = vertx;
  this.sessionMapName = options.getString("mapName", DEFAULT_SESSION_MAP_NAME);
  this.retryTimeout = options.getLong("retryTimeout", DEFAULT_RETRY_TIMEOUT);
  this.random = VertxContextPRNG.current(vertx);

  return this;
}
 
Example #20
Source File: SessionManager.java    From festival with Apache License 2.0 5 votes vote down vote up
private SessionStore getOrCreateSessionStore() throws BeansException {
    SessionStore sessionStore;
    try {
        sessionStore = beanFactory.getBean(SessionStore.class);
    } catch (NoSuchBeanException e) {
        sessionStore = LocalSessionStore.create(vertx);
    }
    return sessionStore;
}
 
Example #21
Source File: AuthHandlerTestBase.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
protected void testAuthorization(String username, boolean fail, Authorization authority) throws Exception {
  if (requiresSession()) {
    router.route().handler(BodyHandler.create());
    SessionStore store = getSessionStore();
    router.route().handler(SessionHandler.create(store));
  }
  AuthenticationProvider authNProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties");
  AuthorizationProvider authZProvider = PropertyFileAuthorization.create(vertx, "login/loginusers.properties");

  AuthenticationHandler authNHandler = createAuthHandler(authNProvider);
  router.route().handler(rc -> {
    // we need to be logged in
    if (rc.user() == null) {
      JsonObject authInfo = new JsonObject().put("username", username).put("password", "delicious:sausages");
      authNProvider.authenticate(authInfo, res -> {
        if (res.succeeded()) {
          rc.setUser(res.result());
          rc.next();
        } else {
          rc.fail(res.cause());
        }
      });
    }
  });
  router.route().handler(authNHandler);
  if (authority != null) {
    router.route().handler(AuthorizationHandler.create(authority).addAuthorizationProvider(authZProvider));
  }
  router.route().handler(rc -> rc.response().end());

  testRequest(HttpMethod.GET, "/", fail ? 403: 200, fail? "Forbidden": "OK");
}
 
Example #22
Source File: CookieSessionStoreImpl.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Override
public SessionStore init(Vertx vertx, JsonObject options) {
  // initialize a secure random
  this.random = VertxContextPRNG.current(vertx);

  try {
    mac = Mac.getInstance("HmacSHA256");
    mac.init(new SecretKeySpec(options.getString("secret").getBytes(), "HmacSHA256"));
  } catch (NoSuchAlgorithmException | InvalidKeyException e) {
    throw new RuntimeException(e);
  }

  return this;
}
 
Example #23
Source File: SessionHandlerFactory.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
public io.vertx.reactivex.ext.web.handler.SessionHandler getObject() {
    SessionStore sessionStore = LocalSessionStore.create(vertx).getDelegate();
    return io.vertx.reactivex.ext.web.handler.SessionHandler.newInstance(new SessionHandlerImpl(DEFAULT_SESSION_COOKIE_NAME, DEFAULT_SESSION_COOKIE_PATH, DEFAULT_SESSION_TIMEOUT, DEFAULT_NAG_HTTPS, DEFAULT_COOKIE_SECURE_FLAG, DEFAULT_COOKIE_HTTP_ONLY_FLAG, DEFAULT_SESSIONID_MIN_LENGTH, sessionStore)
            .setCookieHttpOnlyFlag(true)
            .setSessionCookieName(environment.getProperty("http.cookie.session.name", String.class, DEFAULT_SESSION_COOKIE_NAME))
            .setSessionCookiePath("/" + domain.getPath())
            .setSessionTimeout(environment.getProperty("http.cookie.session.timeout", Long.class, DEFAULT_SESSION_TIMEOUT))
            .setCookieSecureFlag(environment.getProperty("http.cookie.secure", Boolean.class, false))
            .setAuthProvider(userAuthProvider));
}
 
Example #24
Source File: SessionHandlerImpl.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
public SessionHandlerImpl(String sessionCookieName, String sessionCookiePath, long sessionTimeout, boolean nagHttps,
                          boolean sessionCookieSecure, boolean sessionCookieHttpOnly, int minLength, SessionStore sessionStore) {
    this.sessionCookieName = sessionCookieName;
    this.sessionCookiePath = sessionCookiePath;
    this.sessionTimeout = sessionTimeout;
    this.nagHttps = nagHttps;
    this.sessionStore = sessionStore;
    this.sessionCookieSecure = sessionCookieSecure;
    this.sessionCookieHttpOnly = sessionCookieHttpOnly;
    this.minLength = minLength;
}
 
Example #25
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendRequiresAuthorityHasAuthority() throws Exception {
  sockJSHandler.bridge(PropertyFileAuthorization.create(vertx, "login/loginusers.properties"), defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("bang_sticks")), null);
  router.clear();
  SessionStore store = LocalSessionStore.create(vertx);
  router.route().handler(SessionHandler.create(store));
  AuthenticationProvider authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties");
  addLoginHandler(router, authProvider);
  router.route("/eventbus/*").handler(sockJSHandler);
  testSend("foo");
}
 
Example #26
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendRequiresAuthorityHasnotAuthority() throws Exception {
  sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("pick_nose")));
  router.clear();
  SessionStore store = LocalSessionStore.create(vertx);
  router.route().handler(SessionHandler.create(store));
  AuthenticationProvider authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties");
  addLoginHandler(router, authProvider);
  router.route("/eventbus/*").handler(sockJSHandler);
  testError(new JsonObject().put("type", "send").put("address", addr).put("body", "foo"), "access_denied");
}
 
Example #27
Source File: SessionManager.java    From festival with Apache License 2.0 5 votes vote down vote up
public void registerSessionHandler() throws BeansException {
    SessionStore sessionStore = getOrCreateSessionStore();
    SessionHandler sessionHandler = SessionHandler.create(sessionStore);

    resolveAndSetSessionProperties(sessionHandler);

    AuthProvider authProvider = getAuthProvider();
    if (authProvider != null) {
        sessionHandler.setAuthProvider(authProvider);
    }

    router.route().handler(sessionHandler);
}
 
Example #28
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 5 votes vote down vote up
@Test(timeout = 5000)
public void deleteShouldRemoveSessionFromLocalAndRemote(TestContext context) {
    Vertx vertx = rule.vertx();
    SessionStore sessionStore = NearCacheSessionStore.create(vertx);
    Session session = sessionStore.createSession(DEFAULT_TIMEOUT);
    TestObject testObject = new TestObject("TestObject");
    session.put("TEST_KEY", testObject);

    sessionStore.delete("XY", context.asyncAssertSuccess(u -> {
        doWithLocalSession(context, session, context.asyncAssertSuccess(context::assertNull));
        doWithRemoteSession(context, session, context.asyncAssertSuccess(context::assertNull));
    }));
}
 
Example #29
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 5 votes vote down vote up
@Test
public void createSession(TestContext context) {

    Vertx vertx = rule.vertx();
    SessionStore sessionStore = NearCacheSessionStore.create(vertx);
    long beforeCreationTime = System.currentTimeMillis();
    Session session = sessionStore.createSession(3600);
    assertThat(session.id()).isNotEmpty();
    assertThat(session.timeout()).isEqualTo(3600);
    assertThat(session.lastAccessed()).isCloseTo(beforeCreationTime, Offset.offset(100L));
    assertThat(session.isDestroyed()).isFalse();

}
 
Example #30
Source File: NearCacheSessionStoreIT.java    From vertx-vaadin with MIT License 5 votes vote down vote up
@Test
public void createSession(TestContext context) {

    Vertx vertx = rule.vertx();
    SessionStore sessionStore = NearCacheSessionStore.create(vertx);
    long beforeCreationTime = System.currentTimeMillis();
    Session session = sessionStore.createSession(3600);
    assertThat(session.id()).isNotEmpty();
    assertThat(session.timeout()).isEqualTo(3600);
    assertThat(session.lastAccessed()).isCloseTo(beforeCreationTime, Offset.offset(100L));
    assertThat(session.isDestroyed()).isFalse();

}