use of org.wildfly.clustering.ee.infinispan.TransactionBatch in project wildfly by wildfly.
the class BeanEvictionSchedulerTestCase method test.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
@org.junit.Ignore
public void test() throws Exception {
String name = "bean";
String evictedBeanId = "evicted";
String activeBeanId = "active";
CommandDispatcherFactory dispatcherFactory = mock(CommandDispatcherFactory.class);
CommandDispatcher<BeanGroupEvictionContext<String>> dispatcher = mock(CommandDispatcher.class);
Batcher<TransactionBatch> batcher = mock(Batcher.class);
TransactionBatch batch = mock(TransactionBatch.class);
Evictor<String> evictor = mock(Evictor.class);
PassivationConfiguration<Bean<String, Object>> config = mock(PassivationConfiguration.class);
BeanPassivationConfiguration passivationConfig = mock(BeanPassivationConfiguration.class);
ArgumentCaptor<Command> capturedCommand = ArgumentCaptor.forClass(Command.class);
ArgumentCaptor<BeanGroupEvictionContext> capturedContext = ArgumentCaptor.forClass(BeanGroupEvictionContext.class);
when(dispatcherFactory.createCommandDispatcher(same(name), (BeanGroupEvictionContext<String>) capturedContext.capture())).thenReturn(dispatcher);
when(config.getConfiguration()).thenReturn(passivationConfig);
when(passivationConfig.getMaxSize()).thenReturn(1);
try (Scheduler<String> scheduler = new BeanGroupEvictionScheduler<>(name, batcher, evictor, dispatcherFactory, config)) {
BeanGroupEvictionContext<String> context = capturedContext.getValue();
assertSame(scheduler, context);
scheduler.schedule(evictedBeanId);
verifyZeroInteractions(dispatcher);
scheduler.schedule(activeBeanId);
verify(dispatcher).submitOnCluster(capturedCommand.capture());
when(batcher.createBatch()).thenReturn(batch);
capturedCommand.getValue().execute(context);
verify(evictor).evict(evictedBeanId);
verify(evictor, never()).evict(activeBeanId);
verify(batch).close();
}
verify(dispatcher).close();
}
use of org.wildfly.clustering.ee.infinispan.TransactionBatch in project wildfly by wildfly.
the class InfinispanSSOManagerFactory method createSSOManager.
@Override
public <L, C extends Marshallability> SSOManager<A, D, S, L, TransactionBatch> createSSOManager(SSOManagerConfiguration<L, C> configuration) {
Cache<Key<String>, ?> cache = this.configuration.getCache();
CacheProperties properties = new InfinispanCacheProperties(cache.getCacheConfiguration());
SessionsFactory<Map<D, S>, D, S> sessionsFactory = new CoarseSessionsFactory<>(this.configuration.getCache(), properties);
SSOFactory<Map.Entry<A, AtomicReference<L>>, Map<D, S>, A, D, S, L> factory = new InfinispanSSOFactory<>(this.configuration.getCache(), properties, new MarshalledValueMarshaller<>(configuration.getMarshalledValueFactory(), configuration.getMarshallingContext()), configuration.getLocalContextFactory(), sessionsFactory);
IdentifierFactory<String> idFactory = new AffinityIdentifierFactory<>(configuration.getIdentifierFactory(), cache, this.configuration.getKeyAffinityServiceFactory());
Batcher<TransactionBatch> batcher = new InfinispanBatcher(cache);
return new InfinispanSSOManager<>(factory, idFactory, batcher);
}
use of org.wildfly.clustering.ee.infinispan.TransactionBatch in project wildfly by wildfly.
the class DefaultCacheTestCase method batcher.
@Test
public void batcher() {
Batcher<TransactionBatch> batcher = mock(Batcher.class);
TransactionBatch batch = mock(TransactionBatch.class);
when(this.batcherFactory.createBatcher(this.cache)).thenReturn(batcher);
AdvancedCache<Object, Object> subject = new DefaultCache<>(this.manager, this.batcherFactory, this.cache);
// Validate batching logic
when(batcher.createBatch()).thenReturn(batch);
boolean started = subject.startBatch();
assertTrue(started);
started = subject.startBatch();
assertFalse(started);
// Verify commit
subject.endBatch(true);
verify(batch, never()).discard();
verify(batch).close();
reset(batch);
// Verify re-commit is a no-op
subject.endBatch(true);
verify(batch, never()).close();
verify(batch, never()).discard();
// Verify rollback
started = subject.startBatch();
assertTrue(started);
subject.endBatch(false);
verify(batch).discard();
verify(batch).close();
reset(batch);
// Verify re-rollback is a no-op
subject.endBatch(true);
verify(batch, never()).close();
verify(batch, never()).discard();
}
use of org.wildfly.clustering.ee.infinispan.TransactionBatch in project wildfly by wildfly.
the class InfinispanBatcherFactoryTestCase method nonTransactional.
@Test
public void nonTransactional() {
AdvancedCache<Object, Object> cache = mock(AdvancedCache.class);
Configuration configuration = new ConfigurationBuilder().transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL).build();
when(cache.getAdvancedCache()).thenReturn(cache);
when(cache.getCacheConfiguration()).thenReturn(configuration);
Batcher<TransactionBatch> batcher = this.factory.createBatcher(cache);
assertNull(batcher);
}
use of org.wildfly.clustering.ee.infinispan.TransactionBatch in project wildfly by wildfly.
the class InfinispanBatcherFactoryTestCase method transactional.
@Test
public void transactional() {
AdvancedCache<Object, Object> cache = mock(AdvancedCache.class);
Configuration configuration = new ConfigurationBuilder().transaction().transactionMode(TransactionMode.TRANSACTIONAL).build();
when(cache.getAdvancedCache()).thenReturn(cache);
when(cache.getCacheConfiguration()).thenReturn(configuration);
Batcher<TransactionBatch> batcher = this.factory.createBatcher(cache);
assertNotNull(batcher);
}
Aggregations