@@ -19,7 +19,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.ee.infinispan ;
package org.wildfly.clustering.ee.cache.tx ;
import static org.junit.Assert.* ;
import static org.mockito.Mockito.* ;
@@ -40,20 +40,20 @@
* Unit test for {@link InfinispanBatcher}.
* @author Paul Ferraro
*/
public class InfinispanBatcherTestCase {
public class TransactionalBatcherTestCase {
private final TransactionManager tm = mock(TransactionManager . class);
private final Batcher<TransactionBatch > batcher = new InfinispanBatcher (this . tm);
private final Batcher<TransactionBatch > batcher = new TransactionalBatcher<> (this . tm, RuntimeException :: new );
@After
public void destroy() {
InfinispanBatcher . setCurrentBatch(null );
TransactionalBatcher . setCurrentBatch(null );
}
@Test
public void createExistingActiveBatch() throws Exception {
TransactionBatch existingBatch = mock(TransactionBatch . class);
InfinispanBatcher . setCurrentBatch(existingBatch);
TransactionalBatcher . setCurrentBatch(existingBatch);
when(existingBatch. getState()). thenReturn(Batch . State . ACTIVE );
when(existingBatch. interpose()). thenReturn(existingBatch);
@@ -71,7 +71,7 @@ public void createExistingClosedBatch() throws Exception {
Transaction tx = mock(Transaction . class);
ArgumentCaptor<Synchronization > capturedSync = ArgumentCaptor . forClass(Synchronization . class);
InfinispanBatcher . setCurrentBatch(existingBatch);
TransactionalBatcher . setCurrentBatch(existingBatch);
when(existingBatch. getState()). thenReturn(Batch . State . CLOSED );
when(this . tm. getTransaction()). thenReturn(tx);
@@ -81,14 +81,14 @@ public void createExistingClosedBatch() throws Exception {
verify(tx). registerSynchronization(capturedSync. capture());
assertSame(tx, batch. getTransaction());
assertSame(batch, InfinispanBatcher . getCurrentBatch());
assertSame(batch, TransactionalBatcher . getCurrentBatch());
} finally {
capturedSync. getValue(). afterCompletion(Status . STATUS_COMMITTED );
}
verify(tx). commit();
assertNull(InfinispanBatcher . getCurrentBatch());
assertNull(TransactionalBatcher . getCurrentBatch());
}
@@ -110,7 +110,7 @@ public void createBatchClose() throws Exception {
verify(tx). commit();
assertNull(InfinispanBatcher . getCurrentBatch());
assertNull(TransactionalBatcher . getCurrentBatch());
}
@Test
@@ -134,7 +134,7 @@ public void createBatchDiscard() throws Exception {
verify(tx, never()). commit();
verify(tx). rollback();
assertNull(InfinispanBatcher . getCurrentBatch());
assertNull(TransactionalBatcher . getCurrentBatch());
}
@Test
@@ -167,7 +167,7 @@ public void createNestedBatchClose() throws Exception {
verify(tx, never()). rollback();
verify(tx). commit();
assertNull(InfinispanBatcher . getCurrentBatch());
assertNull(TransactionalBatcher . getCurrentBatch());
}
@Test
@@ -202,7 +202,7 @@ public void createNestedBatchDiscard() throws Exception {
verify(tx). rollback();
verify(tx, never()). commit();
assertNull(InfinispanBatcher . getCurrentBatch());
assertNull(TransactionalBatcher . getCurrentBatch());
}
@SuppressWarnings (" resource" )
@@ -240,7 +240,7 @@ public void createOverlappingBatchClose() throws Exception {
verify(tx, never()). rollback();
verify(tx). commit();
assertNull(InfinispanBatcher . getCurrentBatch());
assertNull(TransactionalBatcher . getCurrentBatch());
}
@SuppressWarnings (" resource" )
@@ -280,34 +280,34 @@ public void createOverlappingBatchDiscard() throws Exception {
verify(tx). rollback();
verify(tx, never()). commit();
assertNull(InfinispanBatcher . getCurrentBatch());
assertNull(TransactionalBatcher . getCurrentBatch());
}
@Test
public void resumeNullBatch() throws Exception {
TransactionBatch batch = mock(TransactionBatch . class);
InfinispanBatcher . setCurrentBatch(batch);
TransactionalBatcher . setCurrentBatch(batch);
try (BatchContext context = this . batcher. resumeBatch(null )) {
verifyZeroInteractions(this . tm);
assertNull(InfinispanBatcher . getCurrentBatch());
assertNull(TransactionalBatcher . getCurrentBatch());
}
verifyZeroInteractions(this . tm);
assertSame(batch, InfinispanBatcher . getCurrentBatch());
assertSame(batch, TransactionalBatcher . getCurrentBatch());
}
@Test
public void resumeNonTxBatch() throws Exception {
TransactionBatch existingBatch = mock(TransactionBatch . class);
InfinispanBatcher . setCurrentBatch(existingBatch);
TransactionalBatcher . setCurrentBatch(existingBatch);
TransactionBatch batch = mock(TransactionBatch . class);
try (BatchContext context = this . batcher. resumeBatch(batch)) {
verifyZeroInteractions(this . tm);
assertSame(batch, InfinispanBatcher . getCurrentBatch());
assertSame(batch, TransactionalBatcher . getCurrentBatch());
}
verifyZeroInteractions(this . tm);
assertSame(existingBatch, InfinispanBatcher . getCurrentBatch());
assertSame(existingBatch, TransactionalBatcher . getCurrentBatch());
}
@Test
@@ -322,20 +322,20 @@ public void resumeBatch() throws Exception {
verify(this . tm). resume(tx);
reset(this . tm);
assertSame(batch, InfinispanBatcher . getCurrentBatch());
assertSame(batch, TransactionalBatcher . getCurrentBatch());
}
verify(this . tm). suspend();
verify(this . tm, never()). resume(any());
assertNull(InfinispanBatcher . getCurrentBatch());
assertNull(TransactionalBatcher . getCurrentBatch());
}
@Test
public void resumeBatchExisting() throws Exception {
TransactionBatch existingBatch = mock(TransactionBatch . class);
Transaction existingTx = mock(Transaction . class);
InfinispanBatcher . setCurrentBatch(existingBatch);
TransactionalBatcher . setCurrentBatch(existingBatch);
TransactionBatch batch = mock(TransactionBatch . class);
Transaction tx = mock(Transaction . class);
@@ -347,27 +347,27 @@ public void resumeBatchExisting() throws Exception {
verify(this . tm). resume(tx);
reset(this . tm);
assertSame(batch, InfinispanBatcher . getCurrentBatch());
assertSame(batch, TransactionalBatcher . getCurrentBatch());
when(this . tm. suspend()). thenReturn(tx);
}
verify(this . tm). resume(existingTx);
assertSame(existingBatch, InfinispanBatcher . getCurrentBatch());
assertSame(existingBatch, TransactionalBatcher . getCurrentBatch());
}
@Test
public void suspendBatch() throws Exception {
TransactionBatch batch = mock(TransactionBatch . class);
InfinispanBatcher . setCurrentBatch(batch);
TransactionalBatcher . setCurrentBatch(batch);
TransactionBatch result = this . batcher. suspendBatch();
verify(this . tm). suspend();
assertSame(batch, result);
assertNull(InfinispanBatcher . getCurrentBatch());
assertNull(TransactionalBatcher . getCurrentBatch());
}
@Test