Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-8494 Clear is leaking transaction with Batching
- Loading branch information
1 parent
83c8761
commit 648100e
Showing
6 changed files
with
196 additions
and
193 deletions.
There are no files selected for viewing
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
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
90 changes: 73 additions & 17 deletions
90
core/src/test/java/org/infinispan/api/batch/AbstractBatchTest.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,23 +1,79 @@ | |||
package org.infinispan.api.batch; | package org.infinispan.api.batch; | ||
|
|
||
import java.util.concurrent.atomic.AtomicReference; | import static org.testng.AssertJUnit.assertEquals; | ||
import static org.testng.AssertJUnit.assertNull; | |||
|
|||
import java.lang.reflect.Method; | |||
import java.util.concurrent.Future; | |||
|
|||
import javax.transaction.SystemException; | |||
import javax.transaction.TransactionManager; | |||
|
|
||
import org.infinispan.Cache; | import org.infinispan.Cache; | ||
import org.infinispan.test.AbstractInfinispanTest; | import org.infinispan.manager.EmbeddedCacheManager; | ||
|
import org.infinispan.test.SingleCacheManagerTest; | ||
public abstract class AbstractBatchTest extends AbstractInfinispanTest { | import org.infinispan.test.fwk.TestCacheManagerFactory; | ||
protected String getOnDifferentThread(final Cache<String, String> cache, final String key) throws InterruptedException { | import org.testng.annotations.Test; | ||
final AtomicReference<String> ref = new AtomicReference<String>(); |
|
||
Thread t = new Thread() { | @Test(groups = {"functional", "transaction", "smoke"}) | ||
public void run() { | public abstract class AbstractBatchTest extends SingleCacheManagerTest { | ||
cache.startBatch(); |
|
||
ref.set(cache.get(key)); | @Override | ||
cache.endBatch(true); | public EmbeddedCacheManager createCacheManager() { | ||
} | return TestCacheManagerFactory.createCacheManager(false); | ||
}; | } | ||
|
|
||
t.start(); | public void testClearInBatch(Method method) { | ||
t.join(); | //tests if the clear doesn't leak the batch transaction. | ||
return ref.get(); | //if it does, the get() will be executed against a committed transaction and it will fail. | ||
Cache<String, String> cache = createCache(method.getName()); | |||
cache.put("k2", "v2"); | |||
|
|||
cache.startBatch(); | |||
cache.clear(); | |||
cache.put("k1", "v1"); | |||
cache.endBatch(true); | |||
|
|||
assertEquals(null, cache.get("k2")); | |||
assertEquals("v1", cache.get("k1")); | |||
} | } | ||
|
|||
public void testPutForExternalReadInBatch(Method method) { | |||
//tests if the putForExternalRead doesn't leak the batch transaction. | |||
//if it does, the get() will be executed against a committed transaction and it will fail. | |||
Cache<String, String> cache = createCache(method.getName()); | |||
|
|||
cache.startBatch(); | |||
cache.putForExternalRead("k1", "v1"); | |||
cache.put("k2", "v2"); | |||
cache.endBatch(true); | |||
|
|||
assertEquals("v1", cache.get("k1")); | |||
assertEquals("v2", cache.get("k2")); | |||
|
|||
cache.startBatch(); | |||
cache.putForExternalRead("k3", "v3"); | |||
cache.put("k1", "v2"); | |||
cache.endBatch(false); | |||
|
|||
assertEquals("v1", cache.get("k1")); | |||
assertEquals("v2", cache.get("k2")); | |||
assertEquals("v3", cache.get("k3")); | |||
} | |||
|
|||
String getOnDifferentThread(final Cache<String, String> cache, final String key) throws Exception { | |||
Future<String> f = fork(() -> { | |||
cache.startBatch(); | |||
String v = cache.get(key); | |||
cache.endBatch(true); | |||
return v; | |||
}); | |||
return f.get(); | |||
} | |||
|
|||
void assertNoTransaction(TransactionManager transactionManager) throws SystemException { | |||
assertNull("Should have no ongoing txs", transactionManager.getTransaction()); | |||
} | |||
|
|||
protected abstract <K, V> Cache<K, V> createCache(String name); | |||
} | } |
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
Oops, something went wrong.