Search in sources :

Example 1 with SessionImpl

use of io.vertx.ext.web.sstore.impl.SessionImpl in project vertx-web by vert-x3.

the class SessionHandlerTestBase method testVersion.

@Test
public void testVersion() throws Exception {
    SessionImpl session = (SessionImpl) store.createSession(10000);
    assertEquals(0, session.version());
    session.put("k", "v");
    store.put(session, res -> {
        if (res.failed()) {
            fail("failed to store");
        }
        store.get(session.id(), res1 -> {
            if (res1.failed()) {
                fail("failed to store");
            }
            SessionImpl session1 = (SessionImpl) res1.result();
            // session was stored for the first time so it must have version 1
            assertEquals(1, session1.version());
            // confirm that the content is present
            assertEquals("v", session1.get("k"));
            store.put(session1, res2 -> {
                if (res2.failed()) {
                    fail("failed to store");
                }
                store.get(session1.id(), res3 -> {
                    if (res3.failed()) {
                        fail("failed to store");
                    }
                    SessionImpl session2 = (SessionImpl) res3.result();
                    // session was stored again but no changes were applied to the content
                    // therefore version should remain the same
                    assertEquals(1, session2.version());
                    // confirm the content is present
                    assertEquals("v", session2.get("k"));
                    // update content
                    session2.put("k", "w");
                    store.put(session2, res4 -> {
                        if (res4.failed()) {
                            fail("failed to store");
                        }
                        store.get(session2.id(), res5 -> {
                            if (res5.failed()) {
                                fail("failed to store");
                            }
                            SessionImpl session3 = (SessionImpl) res5.result();
                            // session was stored again but changes were applied to the content
                            // therefore version should must increment
                            assertEquals(2, session3.version());
                            // confirm the content is present
                            assertEquals("w", session3.get("k"));
                            testComplete();
                        });
                    });
                });
            });
        });
    });
    await();
}
Also used : SessionImpl(io.vertx.ext.web.sstore.impl.SessionImpl) Test(org.junit.Test)

Example 2 with SessionImpl

use of io.vertx.ext.web.sstore.impl.SessionImpl in project vertx-web by vert-x3.

the class ClusteredSessionHandlerTest method testSessionSerializationNullPrincipal.

@Test
public void testSessionSerializationNullPrincipal() {
    long timeout = 123;
    SessionImpl session = (SessionImpl) store.createSession(timeout);
    session.setAccessed();
    long lastAccessed = session.lastAccessed();
    stuffSession(session);
    checkSession(session);
    Buffer buffer = Buffer.buffer();
    session.writeToBuffer(buffer);
    SessionImpl session2 = (SessionImpl) store.createSession(0);
    session2.readFromBuffer(0, buffer);
    checkSession(session2);
    assertEquals(timeout, session2.timeout());
    assertEquals(lastAccessed, session2.lastAccessed());
    assertEquals(session.id(), session2.id());
}
Also used : Buffer(io.vertx.core.buffer.Buffer) SessionImpl(io.vertx.ext.web.sstore.impl.SessionImpl) Test(org.junit.Test)

Aggregations

SessionImpl (io.vertx.ext.web.sstore.impl.SessionImpl)2 Test (org.junit.Test)2 Buffer (io.vertx.core.buffer.Buffer)1