@Test public void saveUpdatedLastAccessedTimeFlushModeImmediate() { verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean()); this.repository.setHazelcastFlushMode(HazelcastFlushMode.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); }
@Test public void saveUpdatedAttributeFlushModeImmediate() { verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean()); this.repository.setHazelcastFlushMode(HazelcastFlushMode.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); }
@Test public void removeAttributeFlushModeImmediate() { verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean()); this.repository.setHazelcastFlushMode(HazelcastFlushMode.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); }
@Test public void saveUpdatedMaxInactiveIntervalInSecondsFlushModeImmediate() { verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean()); this.repository.setHazelcastFlushMode(HazelcastFlushMode.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); }
@Override public void save(HazelcastSession session) { if (session.isNew) { this.sessions.set(session.getId(), session.getDelegate(), session.getMaxInactiveInterval().getSeconds(), TimeUnit.SECONDS); } else if (session.sessionIdChanged) { this.sessions.delete(session.originalId); session.originalId = session.getId(); this.sessions.set(session.getId(), session.getDelegate(), session.getMaxInactiveInterval().getSeconds(), TimeUnit.SECONDS); } else if (session.hasChanges()) { SessionUpdateEntryProcessor entryProcessor = new SessionUpdateEntryProcessor(); if (session.lastAccessedTimeChanged) { entryProcessor.setLastAccessedTime(session.getLastAccessedTime()); } if (session.maxInactiveIntervalChanged) { if (SUPPORTS_SET_TTL) { updateTtl(session); } entryProcessor.setMaxInactiveInterval(session.getMaxInactiveInterval()); } if (!session.delta.isEmpty()) { entryProcessor.setDelta(session.delta); } this.sessions.executeOnKey(session.getId(), entryProcessor); } session.clearChangeFlags(); }
@Override public void createInitialState(K key, BucketConfiguration configuration) { JCacheEntryProcessor<K, Nothing> entryProcessor = JCacheEntryProcessor.initStateProcessor(configuration); cache.executeOnKey(key, adoptEntryProcessor(entryProcessor)); }
@Override public <T extends Serializable> CommandResult<T> execute(K key, GridCommand<T> command) { JCacheEntryProcessor<K, T> entryProcessor = JCacheEntryProcessor.executeProcessor(command); return (CommandResult<T>) cache.executeOnKey(key, adoptEntryProcessor(entryProcessor)); }
@Override public void reset() { versionMap.executeOnKey(ReferenceKey.KEY, IncrementVersionEntryProcessor.getInstance()); localReference.reset(); }
private long getVersion() { // try a standard get to give the near-cache a chance Long version = versionMap.get(ReferenceKey.KEY); if (version == null) { version = (Long) versionMap.executeOnKey(ReferenceKey.KEY, GetOrInitVersionEntryProcessor.getInstance()); } return version; }
private Long getVersion(K key) { // try a standard get first to give the near-cache a chance Long version = versionMap.get(key); if (version == null) { version = (Long) versionMap.executeOnKey(key, GetOrInitVersionEntryProcessor.getInstance()); } return version; }
@Override public <T extends Serializable> CommandResult<T> execute(K key, GridCommand<T> command) { JCacheEntryProcessor<K, T> entryProcessor = JCacheEntryProcessor.executeProcessor(command); return (CommandResult<T>) cache.executeOnKey(key, adoptEntryProcessor(entryProcessor)); }
@Override public <T extends Serializable> T createInitialStateAndExecute(K key, BucketConfiguration configuration, GridCommand<T> command) { JCacheEntryProcessor<K, T> entryProcessor = JCacheEntryProcessor.initStateAndExecuteProcessor(command, configuration); CommandResult<T> result = (CommandResult<T>) cache.executeOnKey(key, adoptEntryProcessor(entryProcessor)); return result.getData(); }
@AfterRun public void afterRun(ThreadState state) { // for each worker-thread we store the number of items it has produced for each estimator. for (int k = 0; k < estimatorCount; k++) { CardinalityEstimator estimator = estimators[k]; // the number of unique items produced is equal to the iteration. If items 0,10,20 are produced, // then iteration is 3. long iteration = state.iterations[k]; expectedCountMap.executeOnKey(estimator.getName(), new IncEntryProcessor(iteration)); } }
@Override public <T extends Serializable> T createInitialStateAndExecute(K key, BucketConfiguration configuration, GridCommand<T> command) { JCacheEntryProcessor<K, T> entryProcessor = JCacheEntryProcessor.initStateAndExecuteProcessor(command, configuration); CommandResult<T> result = (CommandResult<T>) cache.executeOnKey(key, adoptEntryProcessor(entryProcessor)); return result.getData(); }
@Override public boolean update(final Object key, final Object newValue, final Object newVersion, final SoftLock lock) { if (lock instanceof MarkerWrapper) { final ExpiryMarker unwrappedMarker = ((MarkerWrapper) lock).getMarker(); return (Boolean) map.executeOnKey(key, new UpdateEntryProcessor(unwrappedMarker, newValue, newVersion, nextMarkerId(), nextTimestamp(hazelcastInstance))); } else { return false; } }
@Override public SoftLock tryLock(final Object key, final Object version) { long timeout = nextTimestamp(hazelcastInstance) + lockTimeout; final ExpiryMarker marker = (ExpiryMarker) map.executeOnKey(key, new LockEntryProcessor(nextMarkerId(), timeout, version)); return new MarkerWrapper(marker); }
@Override public void unlock(final Object key, final SoftLock lock) { if (lock instanceof MarkerWrapper) { final ExpiryMarker unwrappedMarker = ((MarkerWrapper) lock).getMarker(); map.executeOnKey(key, new UnlockEntryProcessor(unwrappedMarker, nextMarkerId(), nextTimestamp(hazelcastInstance))); } }
public boolean update(final Object key, final Object newValue, final Object newVersion, final SoftLock lock) { if (lock instanceof MarkerWrapper) { final ExpiryMarker unwrappedMarker = ((MarkerWrapper) lock).getMarker(); return (Boolean) map.executeOnKey(key, new UpdateEntryProcessor(unwrappedMarker, newValue, newVersion, nextMarkerId(), nextTimestamp(hazelcastInstance))); } else { return false; } }
@TimeStep public void timeStep(ThreadState state) { int key = keys[state.randomInt(keys.length)]; long increment = state.randomInt(100); int delayMs = state.calculateDelay(); map.executeOnKey(key, new IncrementEntryProcessor(increment, delayMs)); state.localIncrementsAtKey[key] += increment; }
@Override public void unlock(final Object key, final SoftLock lock) { if (lock instanceof MarkerWrapper) { final ExpiryMarker unwrappedMarker = ((MarkerWrapper) lock).getMarker(); map.executeOnKey(key, new UnlockEntryProcessor(unwrappedMarker, nextMarkerId(), nextTimestamp(hazelcastInstance))); } }