You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/08/23 10:48:46 UTC

[GitHub] [ignite-3] ygerzhedovich commented on a diff in pull request #1004: IGNITE-17359 Sql. Implement session auto expiration

ygerzhedovich commented on code in PR #1004:
URL: https://github.com/apache/ignite-3/pull/1004#discussion_r952454365


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/session/SessionManagerTest.java:
##########
@@ -0,0 +1,128 @@
+package org.apache.ignite.internal.sql.engine.session;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.util.Map;
+import java.util.UUID;
+import javax.validation.constraints.AssertTrue;
+import org.apache.ignite.internal.sql.engine.property.PropertiesHolder;
+import org.apache.ignite.internal.sql.engine.property.Property;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class SessionManagerTest {
+
+    private SessionManager sessionMgr;
+    private Map<SessionId, Session> activeSessions;
+
+    @BeforeEach
+    void beforeEach() {
+        sessionMgr = new SessionManager("test", System::currentTimeMillis);
+        activeSessions = IgniteTestUtils.getFieldValue(sessionMgr, "activeSessions");
+    }
+
+    @AfterEach
+    void afterEach() throws Exception {
+        sessionMgr.stop();
+    }
+
+    @Test
+    void createSession() {
+        assertEquals(0, activeSessions.size());
+
+        SessionId sessionId1 = sessionMgr.createSession(1000, null);
+        assertNotNull(sessionId1);
+
+        SessionId sessionId2 = sessionMgr.createSession(1000, null);
+        assertNotNull(sessionId2);
+
+        assertNotEquals(sessionId1, sessionId2);
+        assertEquals(2, activeSessions.size());
+    }
+
+    @Test
+    void sessionGet() {
+        PropertiesHolder propHldr = createPropertyHolder();
+
+        SessionId sessionId = sessionMgr.createSession(12345, propHldr);
+
+        Session session = sessionMgr.session(sessionId);
+        assertNotNull(session);
+        assertSame(propHldr, session.queryProperties());
+        assertEquals(12345, session.getIdleTimeoutMs());
+
+        SessionId unknownSessionId = new SessionId(UUID.randomUUID());
+        assertNull(sessionMgr.session(unknownSessionId));
+    }
+
+    @Test
+    void touchSessionDuringGet() throws InterruptedException {

Review Comment:
   @korlov42 In general I agree with you, however not all cases could be checked without `Thread.sleep()`, a s example we should check that session is prolonging expiration time after touch. WDYT, could we keep this part and rework another one?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org