com.hazelcast.map.listener.MapListener Java Examples

The following examples show how to use com.hazelcast.map.listener.MapListener. 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: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
void saveWithSaveModeAlways() {
	verify(this.sessions).addEntryListener(any(MapListener.class), anyBoolean());
	this.repository.setSaveMode(SaveMode.ALWAYS);
	MapSession delegate = new MapSession();
	delegate.setAttribute("attribute1", "value1");
	delegate.setAttribute("attribute2", "value2");
	delegate.setAttribute("attribute3", "value3");
	HazelcastSession session = this.repository.new HazelcastSession(delegate, false);
	session.getAttribute("attribute2");
	session.setAttribute("attribute3", "value4");
	this.repository.save(session);
	ArgumentCaptor<SessionUpdateEntryProcessor> captor = ArgumentCaptor.forClass(SessionUpdateEntryProcessor.class);
	verify(this.sessions).executeOnKey(eq(session.getId()), captor.capture());
	assertThat((Map<String, Object>) ReflectionTestUtils.getField(captor.getValue(), "delta")).hasSize(3);
	verifyZeroInteractions(this.sessions);
}
 
Example #2
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
void saveWithSaveModeOnGetAttribute() {
	verify(this.sessions).addEntryListener(any(MapListener.class), anyBoolean());
	this.repository.setSaveMode(SaveMode.ON_GET_ATTRIBUTE);
	MapSession delegate = new MapSession();
	delegate.setAttribute("attribute1", "value1");
	delegate.setAttribute("attribute2", "value2");
	delegate.setAttribute("attribute3", "value3");
	HazelcastSession session = this.repository.new HazelcastSession(delegate, false);
	session.getAttribute("attribute2");
	session.setAttribute("attribute3", "value4");
	this.repository.save(session);
	ArgumentCaptor<SessionUpdateEntryProcessor> captor = ArgumentCaptor.forClass(SessionUpdateEntryProcessor.class);
	verify(this.sessions).executeOnKey(eq(session.getId()), captor.capture());
	assertThat((Map<String, Object>) ReflectionTestUtils.getField(captor.getValue(), "delta")).hasSize(2);
	verifyZeroInteractions(this.sessions);
}
 
Example #3
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
void saveWithSaveModeOnSetAttribute() {
	verify(this.sessions).addEntryListener(any(MapListener.class), anyBoolean());
	this.repository.setSaveMode(SaveMode.ON_SET_ATTRIBUTE);
	MapSession delegate = new MapSession();
	delegate.setAttribute("attribute1", "value1");
	delegate.setAttribute("attribute2", "value2");
	delegate.setAttribute("attribute3", "value3");
	HazelcastSession session = this.repository.new HazelcastSession(delegate, false);
	session.getAttribute("attribute2");
	session.setAttribute("attribute3", "value4");
	this.repository.save(session);
	ArgumentCaptor<SessionUpdateEntryProcessor> captor = ArgumentCaptor.forClass(SessionUpdateEntryProcessor.class);
	verify(this.sessions).executeOnKey(eq(session.getId()), captor.capture());
	assertThat((Map<String, Object>) ReflectionTestUtils.getField(captor.getValue(), "delta")).hasSize(1);
	verifyZeroInteractions(this.sessions);
}
 
Example #4
Source File: HazelcastEventStore.java    From Moss with Apache License 2.0 6 votes vote down vote up
public HazelcastEventStore(int maxLogSizePerAggregate, IMap<InstanceId, List<InstanceEvent>> eventLog) {
    super(maxLogSizePerAggregate, eventLog);

    eventLog.addEntryListener((MapListener) new EntryAdapter<InstanceId, List<InstanceEvent>>() {
        @Override
        public void entryUpdated(EntryEvent<InstanceId, List<InstanceEvent>> event) {
            log.debug("Updated {}", event);
            long lastKnownVersion = getLastVersion(event.getOldValue());
            List<InstanceEvent> newEvents = event.getValue()
                                                 .stream()
                                                 .filter(e -> e.getVersion() > lastKnownVersion)
                                                 .collect(Collectors.toList());
            HazelcastEventStore.this.publish(newEvents);
        }
    }, true);
}
 
Example #5
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Test
void saveUpdatedMaxInactiveIntervalInSecondsFlushModeImmediate() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	this.repository.setFlushMode(FlushMode.IMMEDIATE);

	HazelcastSession session = this.repository.createSession();
	String sessionId = session.getId();
	session.setMaxInactiveInterval(Duration.ofSeconds(1));
	verify(this.sessions, times(1)).set(eq(sessionId), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));
	verify(this.sessions).setTtl(eq(sessionId), anyLong(), any());
	verify(this.sessions, times(1)).executeOnKey(eq(sessionId), any(EntryProcessor.class));

	this.repository.save(session);
	verifyZeroInteractions(this.sessions);
}
 
Example #6
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveUpdatedMaxInactiveIntervalInSecondsFlushModeOnSave() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	HazelcastSession session = this.repository.createSession();
	session.setMaxInactiveInterval(Duration.ofSeconds(1));
	verifyZeroInteractions(this.sessions);

	this.repository.save(session);
	verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));
	verifyZeroInteractions(this.sessions);
}
 
Example #7
Source File: HazelcastEventStore.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
public HazelcastEventStore(int maxLogSizePerAggregate, IMap<InstanceId, List<InstanceEvent>> eventLog) {
	super(maxLogSizePerAggregate, eventLog);

	eventLog.addEntryListener((MapListener) new EntryAdapter<InstanceId, List<InstanceEvent>>() {
		@Override
		public void entryUpdated(EntryEvent<InstanceId, List<InstanceEvent>> event) {
			log.debug("Updated {}", event);
			long lastKnownVersion = getLastVersion(event.getOldValue());
			List<InstanceEvent> newEvents = event.getValue().stream()
					.filter((e) -> e.getVersion() > lastKnownVersion).collect(Collectors.toList());
			HazelcastEventStore.this.publish(newEvents);
		}
	}, true);
}
 
Example #8
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void delete() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	String sessionId = "testSessionId";

	this.repository.deleteById(sessionId);

	verify(this.sessions, times(1)).remove(eq(sessionId));
	verifyZeroInteractions(this.sessions);
}
 
Example #9
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void getSessionFound() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	MapSession saved = new MapSession();
	saved.setAttribute("savedName", "savedValue");
	given(this.sessions.get(eq(saved.getId()))).willReturn(saved);

	HazelcastSession session = this.repository.findById(saved.getId());

	assertThat(session.getId()).isEqualTo(saved.getId());
	assertThat(session.<String>getAttribute("savedName")).isEqualTo("savedValue");
	verify(this.sessions, times(1)).get(eq(saved.getId()));
	verifyZeroInteractions(this.sessions);
}
 
Example #10
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void getSessionExpired() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	MapSession expired = new MapSession();
	expired.setLastAccessedTime(Instant.now().minusSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS + 1));
	given(this.sessions.get(eq(expired.getId()))).willReturn(expired);

	HazelcastSession session = this.repository.findById(expired.getId());

	assertThat(session).isNull();
	verify(this.sessions, times(1)).get(eq(expired.getId()));
	verify(this.sessions, times(1)).remove(eq(expired.getId()));
	verifyZeroInteractions(this.sessions);
}
 
Example #11
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void getSessionNotFound() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	String sessionId = "testSessionId";

	HazelcastSession session = this.repository.findById(sessionId);

	assertThat(session).isNull();
	verify(this.sessions, times(1)).get(eq(sessionId));
	verifyZeroInteractions(this.sessions);
}
 
Example #12
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveUnchangedFlushModeImmediate() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	this.repository.setFlushMode(FlushMode.IMMEDIATE);

	HazelcastSession session = this.repository.createSession();
	verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));

	this.repository.save(session);
	verifyZeroInteractions(this.sessions);
}
 
Example #13
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveUnchangedFlushModeOnSave() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	HazelcastSession session = this.repository.createSession();
	this.repository.save(session);
	verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));

	this.repository.save(session);
	verifyZeroInteractions(this.sessions);
}
 
Example #14
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveUpdatedLastAccessedTimeFlushModeImmediate() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	this.repository.setFlushMode(FlushMode.IMMEDIATE);

	HazelcastSession session = this.repository.createSession();
	session.setLastAccessedTime(Instant.now());
	verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));
	verify(this.sessions, times(1)).executeOnKey(eq(session.getId()), any(EntryProcessor.class));

	this.repository.save(session);
	verifyZeroInteractions(this.sessions);
}
 
Example #15
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveUpdatedLastAccessedTimeFlushModeOnSave() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	HazelcastSession session = this.repository.createSession();
	session.setLastAccessedTime(Instant.now());
	verifyZeroInteractions(this.sessions);

	this.repository.save(session);
	verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));
	verifyZeroInteractions(this.sessions);
}
 
Example #16
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void removeAttributeFlushModeImmediate() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	this.repository.setFlushMode(FlushMode.IMMEDIATE);

	HazelcastSession session = this.repository.createSession();
	session.removeAttribute("testName");
	verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));
	verify(this.sessions, times(1)).executeOnKey(eq(session.getId()), any(EntryProcessor.class));

	this.repository.save(session);
	verifyZeroInteractions(this.sessions);
}
 
Example #17
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void removeAttributeFlushModeOnSave() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	HazelcastSession session = this.repository.createSession();
	session.removeAttribute("testName");
	verifyZeroInteractions(this.sessions);

	this.repository.save(session);
	verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));
	verifyZeroInteractions(this.sessions);
}
 
Example #18
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveUpdatedAttributeFlushModeImmediate() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	this.repository.setFlushMode(FlushMode.IMMEDIATE);

	HazelcastSession session = this.repository.createSession();
	session.setAttribute("testName", "testValue");
	verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));
	verify(this.sessions, times(1)).executeOnKey(eq(session.getId()), any(EntryProcessor.class));

	this.repository.save(session);
	verifyZeroInteractions(this.sessions);
}
 
Example #19
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveUpdatedAttributeFlushModeOnSave() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	HazelcastSession session = this.repository.createSession();
	session.setAttribute("testName", "testValue");
	verifyZeroInteractions(this.sessions);

	this.repository.save(session);
	verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));
	verifyZeroInteractions(this.sessions);
}
 
Example #20
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveNewFlushModeImmediate() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	this.repository.setFlushMode(FlushMode.IMMEDIATE);

	HazelcastSession session = this.repository.createSession();
	verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));
	verifyZeroInteractions(this.sessions);
}
 
Example #21
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveNewFlushModeOnSave() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	HazelcastSession session = this.repository.createSession();
	verifyZeroInteractions(this.sessions);

	this.repository.save(session);
	verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class),
			eq(TimeUnit.SECONDS));
	verifyZeroInteractions(this.sessions);
}
 
Example #22
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void createSessionCustomMaxInactiveInterval() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	int interval = 1;
	this.repository.setDefaultMaxInactiveInterval(interval);

	HazelcastSession session = this.repository.createSession();

	assertThat(session.getMaxInactiveInterval()).isEqualTo(Duration.ofSeconds(interval));
	verifyZeroInteractions(this.sessions);
}
 
Example #23
Source File: HazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void createSessionDefaultMaxInactiveInterval() {
	verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());

	HazelcastSession session = this.repository.createSession();

	assertThat(session.getMaxInactiveInterval()).isEqualTo(new MapSession().getMaxInactiveInterval());
	verifyZeroInteractions(this.sessions);
}