use of org.wildfly.clustering.ee.cache.tx.TransactionBatch in project wildfly by wildfly.
the class BeanExpirationSchedulerTestCase method testExpire.
@Test
public void testExpire() throws InterruptedException {
Group group = mock(Group.class);
Batcher<TransactionBatch> batcher = mock(Batcher.class);
TransactionBatch batch = mock(TransactionBatch.class);
BeanFactory<String, Object> factory = mock(BeanFactory.class);
ExpirationConfiguration<Object> config = mock(ExpirationConfiguration.class);
RemoveListener<Object> listener = mock(RemoveListener.class);
BeanEntry<String> entry = mock(BeanEntry.class);
BeanRemover<String, Object> remover = mock(BeanRemover.class);
String beanId = "expiring";
Duration timeout = Duration.ofMillis(10L);
when(group.isSingleton()).thenReturn(true);
when(batcher.createBatch()).thenReturn(batch);
when(config.getTimeout()).thenReturn(timeout);
when(config.getRemoveListener()).thenReturn(listener);
when(entry.getLastAccessedTime()).thenReturn(Instant.now());
when(remover.remove(beanId, listener)).thenReturn(true);
try (Scheduler<String, ImmutableBeanEntry<String>> scheduler = new BeanExpirationScheduler<>(group, batcher, factory, config, remover, Duration.ZERO)) {
scheduler.schedule(beanId, entry);
Thread.sleep(500);
}
verify(batch).close();
}
use of org.wildfly.clustering.ee.cache.tx.TransactionBatch in project wildfly by wildfly.
the class SessionExpirationSchedulerTestCase method test.
@Test
public void test() throws InterruptedException {
Batcher<TransactionBatch> batcher = mock(Batcher.class);
TransactionBatch batch = mock(TransactionBatch.class);
Remover<String> remover = mock(Remover.class);
ImmutableSessionMetaDataFactory<Object> metaDataFactory = mock(ImmutableSessionMetaDataFactory.class);
ImmutableSessionMetaData immortalSessionMetaData = mock(ImmutableSessionMetaData.class);
ImmutableSessionMetaData expiringSessionMetaData = mock(ImmutableSessionMetaData.class);
ImmutableSessionMetaData canceledSessionMetaData = mock(ImmutableSessionMetaData.class);
String immortalSessionId = "immortal";
String expiringSessionId = "expiring";
String canceledSessionId = "canceled";
when(batcher.createBatch()).thenReturn(batch);
when(immortalSessionMetaData.getMaxInactiveInterval()).thenReturn(Duration.ZERO);
when(expiringSessionMetaData.getMaxInactiveInterval()).thenReturn(Duration.ofMillis(1L));
when(canceledSessionMetaData.getMaxInactiveInterval()).thenReturn(Duration.ofSeconds(100L));
Instant now = Instant.now();
when(expiringSessionMetaData.getLastAccessEndTime()).thenReturn(now);
when(canceledSessionMetaData.getLastAccessEndTime()).thenReturn(now);
when(remover.remove(expiringSessionId)).thenReturn(true);
try (Scheduler<String, SessionExpirationMetaData> scheduler = new SessionExpirationScheduler<>(batcher, metaDataFactory, remover, Duration.ZERO)) {
scheduler.schedule(immortalSessionId, immortalSessionMetaData);
scheduler.schedule(canceledSessionId, canceledSessionMetaData);
scheduler.schedule(expiringSessionId, expiringSessionMetaData);
scheduler.cancel(canceledSessionId);
TimeUnit.MILLISECONDS.sleep(500);
}
verify(remover, never()).remove(immortalSessionId);
verify(remover, never()).remove(canceledSessionId);
verify(batch).close();
}
use of org.wildfly.clustering.ee.cache.tx.TransactionBatch in project wildfly by wildfly.
the class BeanExpirationSchedulerTestCase method testImmortal.
@Test
public void testImmortal() throws InterruptedException {
Group group = mock(Group.class);
Batcher<TransactionBatch> batcher = mock(Batcher.class);
BeanFactory<String, Object> factory = mock(BeanFactory.class);
ExpirationConfiguration<Object> config = mock(ExpirationConfiguration.class);
RemoveListener<Object> listener = mock(RemoveListener.class);
BeanEntry<String> entry = mock(BeanEntry.class);
BeanRemover<String, Object> remover = mock(BeanRemover.class);
String beanId = "immortal";
when(group.isSingleton()).thenReturn(true);
// Fun fact: the Jakarta Enterprise Beans specification allows a timeout value of 0, so only negative timeouts are treated as immortal
when(config.getTimeout()).thenReturn(Duration.ofMinutes(-1L));
when(config.getRemoveListener()).thenReturn(listener);
when(entry.getLastAccessedTime()).thenReturn(Instant.now());
try (Scheduler<String, ImmutableBeanEntry<String>> scheduler = new BeanExpirationScheduler<>(group, batcher, factory, config, remover, Duration.ZERO)) {
scheduler.schedule(beanId, entry);
Thread.sleep(500);
}
verify(batcher, never()).createBatch();
verify(remover, never()).remove(beanId, listener);
}
use of org.wildfly.clustering.ee.cache.tx.TransactionBatch in project wildfly by wildfly.
the class BeanExpirationSchedulerTestCase method testNotYetExpired.
@Test
public void testNotYetExpired() throws InterruptedException {
Group group = mock(Group.class);
Batcher<TransactionBatch> batcher = mock(Batcher.class);
TransactionBatch batch = mock(TransactionBatch.class);
BeanFactory<String, Object> factory = mock(BeanFactory.class);
ExpirationConfiguration<Object> config = mock(ExpirationConfiguration.class);
RemoveListener<Object> listener = mock(RemoveListener.class);
BeanEntry<String> entry = mock(BeanEntry.class);
BeanRemover<String, Object> remover = mock(BeanRemover.class);
String beanId = "not-expired";
Duration timeout = Duration.ofMillis(10L);
when(batcher.createBatch()).thenReturn(batch);
when(config.getTimeout()).thenReturn(Duration.ofMillis(1L));
when(config.getRemoveListener()).thenReturn(listener);
when(entry.getLastAccessedTime()).thenReturn(Instant.now().plus(Duration.ofMinutes(1)));
when(factory.findValue(beanId)).thenReturn(entry);
when(entry.isExpired(same(timeout))).thenReturn(false);
try (Scheduler<String, ImmutableBeanEntry<String>> scheduler = new BeanExpirationScheduler<>(group, batcher, factory, config, remover, Duration.ZERO)) {
scheduler.schedule(beanId, entry);
Thread.sleep(500);
}
verify(remover, never()).remove(beanId, listener);
verify(batch, never()).close();
}
use of org.wildfly.clustering.ee.cache.tx.TransactionBatch in project wildfly by wildfly.
the class BeanExpirationSchedulerTestCase method testCancel.
@Test
public void testCancel() throws InterruptedException {
Group group = mock(Group.class);
Batcher<TransactionBatch> batcher = mock(Batcher.class);
BeanFactory<String, Object> factory = mock(BeanFactory.class);
ExpirationConfiguration<Object> config = mock(ExpirationConfiguration.class);
RemoveListener<Object> listener = mock(RemoveListener.class);
BeanEntry<String> entry = mock(BeanEntry.class);
BeanRemover<String, Object> remover = mock(BeanRemover.class);
String beanId = "canceled";
Duration timeout = Duration.ofMinutes(1L);
when(config.getTimeout()).thenReturn(timeout);
when(config.getRemoveListener()).thenReturn(listener);
when(entry.getLastAccessedTime()).thenReturn(Instant.now());
try (Scheduler<String, ImmutableBeanEntry<String>> scheduler = new BeanExpirationScheduler<>(group, batcher, factory, config, remover, Duration.ZERO)) {
scheduler.schedule(beanId, entry);
Thread.sleep(500);
scheduler.cancel(beanId);
}
verify(remover, never()).remove(beanId, listener);
verify(batcher, never()).createBatch();
}
Aggregations