Example usage for org.springframework.session.data.gemfire AbstractGemFireOperationsSessionRepository.GemFireSession AbstractGemFireOperationsSessionRepository.GemFireSession

List of usage examples for org.springframework.session.data.gemfire AbstractGemFireOperationsSessionRepository.GemFireSession AbstractGemFireOperationsSessionRepository.GemFireSession

Introduction

In this page you can find the example usage for org.springframework.session.data.gemfire AbstractGemFireOperationsSessionRepository.GemFireSession AbstractGemFireOperationsSessionRepository.GemFireSession.

Prototype

AbstractGemFireOperationsSessionRepository.GemFireSession

Source Link

Usage

From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java

@Test
public void constructGemFireSessionWithDefaultInitialization() {
    final long beforeOrAtCreationTime = System.currentTimeMillis();

    AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession();

    assertThat(session.getId()).isNotNull();
    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 hasDeltaWhenNoSessionChangesIsFalse() {
    assertThat(new AbstractGemFireOperationsSessionRepository.GemFireSession().hasDelta()).isFalse();
}

From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java

@Test
public void hasDeltaWhenSessionAttributesChangeIsTrue() {
    AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession();

    assertThat(session.hasDelta()).isFalse();

    session.setAttribute("attrOne", "test");

    assertThat(session.hasDelta()).isTrue();
}

From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java

@Test
public void hasDeltaWhenSessionLastAccessedTimeIsUpdatedIsTrue() {
    final long expectedLastAccessTime = 1L;

    AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession();

    assertThat(session.getLastAccessedTime()).isNotEqualTo(expectedLastAccessTime);
    assertThat(session.hasDelta()).isFalse();

    session.setLastAccessedTime(expectedLastAccessTime);

    assertThat(session.getLastAccessedTime()).isEqualTo(expectedLastAccessTime);
    assertThat(session.hasDelta()).isTrue();

    session.setLastAccessedTime(expectedLastAccessTime);

    assertThat(session.getLastAccessedTime()).isEqualTo(expectedLastAccessTime);
    assertThat(session.hasDelta()).isTrue();
}

From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java

@Test
public void hasDeltaWhenSessionMaxInactiveIntervalInSecondsIsUpdatedIsTrue() {
    final int expectedMaxInactiveIntervalInSeconds = 300;

    AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession();

    assertThat(session.getMaxInactiveIntervalInSeconds()).isNotEqualTo(expectedMaxInactiveIntervalInSeconds);
    assertThat(session.hasDelta()).isFalse();

    session.setMaxInactiveIntervalInSeconds(expectedMaxInactiveIntervalInSeconds);

    assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(expectedMaxInactiveIntervalInSeconds);
    assertThat(session.hasDelta()).isTrue();

    session.setMaxInactiveIntervalInSeconds(expectedMaxInactiveIntervalInSeconds);

    assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(expectedMaxInactiveIntervalInSeconds);
    assertThat(session.hasDelta()).isTrue();
}

From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java

@Test
public void sessionToDelta() throws Exception {
    final DataOutput mockDataOutput = mock(DataOutput.class);

    @SuppressWarnings("serial")
    AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession() {
        @Override/*from  w w w.  j  ava  2 s  .c  o  m*/
        void writeObject(Object obj, DataOutput out) throws IOException {
            assertThat(String.valueOf(obj)).isEqualTo("test");
            assertThat(out).isSameAs(mockDataOutput);
        }
    };

    session.setLastAccessedTime(1L);
    session.setMaxInactiveIntervalInSeconds(300);
    session.setAttribute("attrOne", "test");

    assertThat(session.hasDelta()).isTrue();

    session.toDelta(mockDataOutput);

    assertThat(session.hasDelta()).isFalse();

    verify(mockDataOutput, times(1)).writeLong(eq(1L));
    verify(mockDataOutput, times(1)).writeInt(eq(300));
    verify(mockDataOutput, times(1)).writeInt(eq(1));
    verify(mockDataOutput, times(1)).writeUTF(eq("attrOne"));
}

From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java

@Test
public void sessionFromDelta() throws Exception {
    final DataInput mockDataInput = mock(DataInput.class);

    given(mockDataInput.readLong()).willReturn(1L);
    given(mockDataInput.readInt()).willReturn(600).willReturn(0);

    @SuppressWarnings("serial")
    AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession() {
        @Override//from   w w  w .  j  a va 2  s .com
        @SuppressWarnings("unchecked")
        <T> T readObject(DataInput in) throws ClassNotFoundException, IOException {
            assertThat(in).isSameAs(mockDataInput);
            return (T) "test";
        }
    };

    session.fromDelta(mockDataInput);

    assertThat(session.hasDelta()).isFalse();
    assertThat(session.getLastAccessedTime()).isEqualTo(1L);
    assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(600);
    assertThat(session.getAttributeNames().isEmpty()).isTrue();

    verify(mockDataInput, times(1)).readLong();
    verify(mockDataInput, times(2)).readInt();
    verify(mockDataInput, never()).readUTF();
}