Java Code Examples for io.vertx.ext.web.sstore.SessionStore#createSession()

The following examples show how to use io.vertx.ext.web.sstore.SessionStore#createSession() . 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(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 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
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 5
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 6
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 7
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 8
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));
    }));
}