Search in sources :

Example 1 with TransactionBatch

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();
}
Also used : TransactionBatch(org.wildfly.clustering.ee.infinispan.TransactionBatch) BeanPassivationConfiguration(org.wildfly.clustering.ejb.BeanPassivationConfiguration) Bean(org.wildfly.clustering.ejb.Bean) Command(org.wildfly.clustering.dispatcher.Command) CommandDispatcherFactory(org.wildfly.clustering.dispatcher.CommandDispatcherFactory) Test(org.junit.Test)

Example 2 with TransactionBatch

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);
}
Also used : CoarseSessionsFactory(org.wildfly.clustering.web.infinispan.sso.coarse.CoarseSessionsFactory) TransactionBatch(org.wildfly.clustering.ee.infinispan.TransactionBatch) InfinispanBatcher(org.wildfly.clustering.ee.infinispan.InfinispanBatcher) InfinispanCacheProperties(org.wildfly.clustering.ee.infinispan.InfinispanCacheProperties) CacheProperties(org.wildfly.clustering.ee.infinispan.CacheProperties) AffinityIdentifierFactory(org.wildfly.clustering.web.infinispan.AffinityIdentifierFactory) Map(java.util.Map) Key(org.wildfly.clustering.infinispan.spi.distribution.Key) InfinispanCacheProperties(org.wildfly.clustering.ee.infinispan.InfinispanCacheProperties)

Example 3 with TransactionBatch

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();
}
Also used : TransactionBatch(org.wildfly.clustering.ee.infinispan.TransactionBatch) Test(org.junit.Test)

Example 4 with TransactionBatch

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);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Configuration(org.infinispan.configuration.cache.Configuration) TransactionBatch(org.wildfly.clustering.ee.infinispan.TransactionBatch) Test(org.junit.Test)

Example 5 with TransactionBatch

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);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Configuration(org.infinispan.configuration.cache.Configuration) TransactionBatch(org.wildfly.clustering.ee.infinispan.TransactionBatch) Test(org.junit.Test)

Aggregations

TransactionBatch (org.wildfly.clustering.ee.infinispan.TransactionBatch)7 Test (org.junit.Test)5 CommandDispatcherFactory (org.wildfly.clustering.dispatcher.CommandDispatcherFactory)3 Configuration (org.infinispan.configuration.cache.Configuration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 Command (org.wildfly.clustering.dispatcher.Command)2 CacheProperties (org.wildfly.clustering.ee.infinispan.CacheProperties)2 InfinispanBatcher (org.wildfly.clustering.ee.infinispan.InfinispanBatcher)2 InfinispanCacheProperties (org.wildfly.clustering.ee.infinispan.InfinispanCacheProperties)2 Key (org.wildfly.clustering.infinispan.spi.distribution.Key)2 AffinityIdentifierFactory (org.wildfly.clustering.web.infinispan.AffinityIdentifierFactory)2 Map (java.util.Map)1 Address (org.infinispan.remoting.transport.Address)1 Bean (org.wildfly.clustering.ejb.Bean)1 BeanPassivationConfiguration (org.wildfly.clustering.ejb.BeanPassivationConfiguration)1 CoarseSessionsFactory (org.wildfly.clustering.web.infinispan.sso.coarse.CoarseSessionsFactory)1 ImmutableSession (org.wildfly.clustering.web.session.ImmutableSession)1 ImmutableSessionMetaData (org.wildfly.clustering.web.session.ImmutableSessionMetaData)1