-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-1346 Transactional listeners method order problem
added unit test to document and enforce the sequence of notifications on remote and local nodes.
- Loading branch information
1 parent
0b36bcc
commit 3e9d50e
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
core/src/test/java/org/infinispan/tx/TxListenerInvocationSequenceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.infinispan.tx; | ||
|
||
import org.infinispan.configuration.cache.CacheMode; | ||
import org.infinispan.configuration.cache.ConfigurationBuilder; | ||
import org.infinispan.notifications.Listener; | ||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated; | ||
import org.infinispan.notifications.cachelistener.annotation.TransactionCompleted; | ||
import org.infinispan.notifications.cachelistener.annotation.TransactionRegistered; | ||
import org.infinispan.notifications.cachelistener.event.CacheEntryCreatedEvent; | ||
import org.infinispan.notifications.cachelistener.event.TransactionCompletedEvent; | ||
import org.infinispan.notifications.cachelistener.event.TransactionRegisteredEvent; | ||
import org.infinispan.test.MultipleCacheManagersTest; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.testng.AssertJUnit.assertEquals; | ||
|
||
/** | ||
* @author Mircea.Markus@jboss.org | ||
*/ | ||
@Test(groups = "functional", testName = "tx.TxListenerInvocationSequenceTest") | ||
public class TxListenerInvocationSequenceTest extends MultipleCacheManagersTest { | ||
|
||
@Override | ||
protected void createCacheManagers() throws Throwable { | ||
ConfigurationBuilder cacheConfig = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, true); | ||
createClusteredCaches(2, cacheConfig); | ||
waitForClusterToForm(); | ||
} | ||
|
||
public void testSameInvokingSequence() { | ||
TxListener l0 = new TxListener(0); | ||
cache(0).addListener(l0); | ||
TxListener l1 = new TxListener(1); | ||
cache(1).addListener(l1); | ||
cache(0).put("k", "v"); | ||
|
||
assertEquals(l0.log, l1.log); | ||
assertEquals(l0.log,Arrays.asList(TxEvent.STARTED, TxEvent.CREATED, TxEvent.COMPLETED)); | ||
} | ||
|
||
|
||
enum TxEvent { | ||
STARTED, CREATED, COMPLETED | ||
} | ||
|
||
@Listener | ||
public static class TxListener { | ||
|
||
int cacheIndex; | ||
List<TxEvent> log = new ArrayList<TxEvent>(3); | ||
|
||
|
||
public TxListener(int cacheIndex) { | ||
this.cacheIndex = cacheIndex; | ||
} | ||
|
||
@TransactionRegistered | ||
public void startTx(TransactionRegisteredEvent tre) { | ||
if (!tre.isPre()) log.add(TxEvent.STARTED); | ||
} | ||
|
||
@CacheEntryCreated | ||
public void entryCreated(CacheEntryCreatedEvent cec) { | ||
if (cec.isPre()) log.add(TxEvent.CREATED); | ||
} | ||
|
||
@TransactionCompleted | ||
public void txCompleted(TransactionCompletedEvent tce) { | ||
if (!tce.isPre()) log.add(TxEvent.COMPLETED); | ||
} | ||
} | ||
} |