List of usage examples for org.springframework.session.data.gemfire AbstractGemFireOperationsSessionRepository.GemFireSession AbstractGemFireOperationsSessionRepository.GemFireSession
protected GemFireSession(Session session)
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void constructGemFireSessionWithId() { final long beforeOrAtCreationTime = System.currentTimeMillis(); AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession( "1"); assertThat(session.getId()).isEqualTo("1"); assertThat(session.getCreationTime()).isGreaterThanOrEqualTo(beforeOrAtCreationTime); assertThat(session.getLastAccessedTime()).isGreaterThanOrEqualTo(beforeOrAtCreationTime); assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(0); assertThat(session.getAttributeNames()).isNotNull(); assertThat(session.getAttributeNames().isEmpty()).isTrue(); }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void constructGemFireSessionWithSession() { final long expectedCreationTime = 1L; final long expectedLastAccessTime = 2L; ExpiringSession mockSession = mockSession("2", expectedCreationTime, expectedLastAccessTime, MAX_INACTIVE_INTERVAL_IN_SECONDS); Set<String> expectedAttributedNames = asSet("attrOne", "attrTwo"); given(mockSession.getAttributeNames()).willReturn(expectedAttributedNames); given(mockSession.getAttribute(eq("attrOne"))).willReturn("testOne"); given(mockSession.getAttribute(eq("attrTwo"))).willReturn("testTwo"); AbstractGemFireOperationsSessionRepository.GemFireSession gemfireSession = new AbstractGemFireOperationsSessionRepository.GemFireSession( mockSession);/*from w ww . ja va 2 s.c om*/ assertThat(gemfireSession.getId()).isEqualTo("2"); assertThat(gemfireSession.getCreationTime()).isEqualTo(expectedCreationTime); assertThat(gemfireSession.getLastAccessedTime()).isEqualTo(expectedLastAccessTime); assertThat(gemfireSession.getMaxInactiveIntervalInSeconds()).isEqualTo(MAX_INACTIVE_INTERVAL_IN_SECONDS); assertThat(gemfireSession.getAttributeNames()).isEqualTo(expectedAttributedNames); assertThat(String.valueOf(gemfireSession.getAttribute("attrOne"))).isEqualTo("testOne"); assertThat(String.valueOf(gemfireSession.getAttribute("attrTwo"))).isEqualTo("testTwo"); verify(mockSession, times(1)).getId(); verify(mockSession, times(1)).getCreationTime(); verify(mockSession, times(1)).getLastAccessedTime(); verify(mockSession, times(1)).getMaxInactiveIntervalInSeconds(); verify(mockSession, times(1)).getAttributeNames(); verify(mockSession, times(1)).getAttribute(eq("attrOne")); verify(mockSession, times(1)).getAttribute(eq("attrTwo")); }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void constructGemFireSessionWithNullSession() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("The ExpiringSession to copy cannot be null"); new AbstractGemFireOperationsSessionRepository.GemFireSession((ExpiringSession) null); }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void constructGemFireSessionWithUnspecifiedId() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("ID must be specified"); new AbstractGemFireOperationsSessionRepository.GemFireSession(" "); }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void sessionToData() throws Exception { @SuppressWarnings("serial") AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession( "1") { @Override// w w w . ja v a 2s. c o m void writeObject(Object obj, DataOutput out) throws IOException { assertThat(obj) .isInstanceOf(AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes.class); assertThat(out).isNotNull(); } }; session.setLastAccessedTime(123L); session.setMaxInactiveIntervalInSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS); session.setPrincipalName("jblum"); DataOutput mockDataOutput = mock(DataOutput.class); session.toData(mockDataOutput); verify(mockDataOutput, times(1)).writeUTF(eq("1")); verify(mockDataOutput, times(1)).writeLong(eq(session.getCreationTime())); verify(mockDataOutput, times(1)).writeLong(eq(session.getLastAccessedTime())); verify(mockDataOutput, times(1)).writeInt(eq(session.getMaxInactiveIntervalInSeconds())); verify(mockDataOutput, times(1)).writeInt(eq("jblum".length())); verify(mockDataOutput, times(1)).writeUTF(eq(session.getPrincipalName())); }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void sessionFromData() throws Exception { final long expectedCreationTime = 1L; final long expectedLastAccessedTime = 2L; final int expectedMaxInactiveIntervalInSeconds = (int) TimeUnit.HOURS.toSeconds(6); final String expectedPrincipalName = "jblum"; DataInput mockDataInput = mock(DataInput.class); given(mockDataInput.readUTF()).willReturn("2").willReturn(expectedPrincipalName); given(mockDataInput.readLong()).willReturn(expectedCreationTime).willReturn(expectedLastAccessedTime); given(mockDataInput.readInt()).willReturn(expectedMaxInactiveIntervalInSeconds); @SuppressWarnings("serial") AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession( "1") { @Override/* w ww. ja va 2 s . co m*/ @SuppressWarnings("unchecked") <T> T readObject(DataInput in) throws ClassNotFoundException, IOException { assertThat(in).isNotNull(); AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes sessionAttributes = new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes(); sessionAttributes.setAttribute("attrOne", "testOne"); sessionAttributes.setAttribute("attrTwo", "testTwo"); return (T) sessionAttributes; } }; session.fromData(mockDataInput); Set<String> expectedAttributeNames = asSet("attrOne", "attrTwo", FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME); assertThat(session.getId()).isEqualTo("2"); assertThat(session.getCreationTime()).isEqualTo(expectedCreationTime); assertThat(session.getLastAccessedTime()).isEqualTo(expectedLastAccessedTime); assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(expectedMaxInactiveIntervalInSeconds); assertThat(session.getPrincipalName()).isEqualTo(expectedPrincipalName); assertThat(session.getAttributeNames().size()).isEqualTo(3); assertThat(session.getAttributeNames().containsAll(expectedAttributeNames)).isTrue(); assertThat(String.valueOf(session.getAttribute("attrOne"))).isEqualTo("testOne"); assertThat(String.valueOf(session.getAttribute("attrTwo"))).isEqualTo("testTwo"); assertThat(String.valueOf(session.getAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME))) .isEqualTo(expectedPrincipalName); verify(mockDataInput, times(2)).readUTF(); verify(mockDataInput, times(2)).readLong(); verify(mockDataInput, times(2)).readInt(); }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void sessionToDataThenFromDataWhenPrincipalNameIsNullGetsHandledProperly() throws ClassNotFoundException, IOException { final long beforeOrAtCreationTime = System.currentTimeMillis(); @SuppressWarnings("serial") AbstractGemFireOperationsSessionRepository.GemFireSession expectedSession = new AbstractGemFireOperationsSessionRepository.GemFireSession( "123") { @Override//from w w w .ja va 2 s.c o m void writeObject(Object obj, DataOutput out) throws IOException { assertThat(obj) .isInstanceOf(AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes.class); assertThat(out).isNotNull(); } }; assertThat(expectedSession.getId()).isEqualTo("123"); assertThat(expectedSession.getCreationTime()).isGreaterThanOrEqualTo(beforeOrAtCreationTime); assertThat(expectedSession.getLastAccessedTime()).isGreaterThanOrEqualTo(expectedSession.getCreationTime()); assertThat(expectedSession.getMaxInactiveIntervalInSeconds()).isEqualTo(0); assertThat(expectedSession.getPrincipalName()).isNull(); ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); expectedSession.toData(new DataOutputStream(outBytes)); @SuppressWarnings("serial") AbstractGemFireOperationsSessionRepository.GemFireSession deserializedSession = new AbstractGemFireOperationsSessionRepository.GemFireSession( "0") { @Override @SuppressWarnings("unchecked") <T> T readObject(DataInput in) throws ClassNotFoundException, IOException { return (T) new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes(); } }; deserializedSession.fromData(new DataInputStream(new ByteArrayInputStream(outBytes.toByteArray()))); assertThat(deserializedSession).isEqualTo(expectedSession); assertThat(deserializedSession.getCreationTime()).isEqualTo(expectedSession.getCreationTime()); assertThat(deserializedSession.getLastAccessedTime()).isEqualTo(expectedSession.getLastAccessedTime()); assertThat(deserializedSession.getMaxInactiveIntervalInSeconds()) .isEqualTo(expectedSession.getMaxInactiveIntervalInSeconds()); assertThat(deserializedSession.getPrincipalName()).isNull(); }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void sessionComparisons() { final long twoHoursAgo = (System.currentTimeMillis() - TimeUnit.HOURS.toMillis(2)); AbstractGemFireOperationsSessionRepository.GemFireSession sessionOne = new AbstractGemFireOperationsSessionRepository.GemFireSession( mockSession("1", twoHoursAgo, MAX_INACTIVE_INTERVAL_IN_SECONDS)); AbstractGemFireOperationsSessionRepository.GemFireSession sessionTwo = new AbstractGemFireOperationsSessionRepository.GemFireSession( "2"); assertThat(sessionOne.getCreationTime()).isEqualTo(twoHoursAgo); assertThat(sessionTwo.getCreationTime()).isGreaterThan(twoHoursAgo); assertThat(sessionOne.compareTo(sessionTwo)).isLessThan(0); assertThat(sessionOne.compareTo(sessionOne)).isEqualTo(0); assertThat(sessionTwo.compareTo(sessionOne)).isGreaterThan(0); }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void sessionEqualsDifferentSessionBasedOnId() { AbstractGemFireOperationsSessionRepository.GemFireSession sessionOne = new AbstractGemFireOperationsSessionRepository.GemFireSession( "1"); sessionOne.setLastAccessedTime(12345L); sessionOne.setMaxInactiveIntervalInSeconds(120); sessionOne.setPrincipalName("jblum"); AbstractGemFireOperationsSessionRepository.GemFireSession sessionTwo = new AbstractGemFireOperationsSessionRepository.GemFireSession( "1"); sessionTwo.setLastAccessedTime(67890L); sessionTwo.setMaxInactiveIntervalInSeconds(300); sessionTwo.setPrincipalName("rwinch"); assertThat(sessionOne.getId().equals(sessionTwo.getId())).isTrue(); assertThat(sessionOne.getLastAccessedTime() == sessionTwo.getLastAccessedTime()).isFalse(); assertThat(sessionOne.getMaxInactiveIntervalInSeconds() == sessionTwo.getMaxInactiveIntervalInSeconds()) .isFalse();//from ww w .j a va 2 s .c om assertThat(sessionOne.getPrincipalName().equals(sessionTwo.getPrincipalName())).isFalse(); assertThat(sessionOne.equals(sessionTwo)).isTrue(); }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void sessionHashCodeIsNotEqualToStringIdHashCode() { AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession( "1"); assertThat(session.getId()).isEqualTo("1"); assertThat(session.hashCode()).isNotEqualTo("1".hashCode()); }