From 2da3fb5f9f25f08135709c7006e7293837d1eb22 Mon Sep 17 00:00:00 2001 From: Pavel Nikitin Date: Fri, 22 Jul 2016 16:04:00 +0200 Subject: [PATCH 1/2] fix ArrayIndexOutOfBoundsException --- .../iterate/EntityIdArrayCachedInstanceIterable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entity-store/src/main/java/jetbrains/exodus/entitystore/iterate/EntityIdArrayCachedInstanceIterable.java b/entity-store/src/main/java/jetbrains/exodus/entitystore/iterate/EntityIdArrayCachedInstanceIterable.java index 14fe9e2e6..7f1ea4c6d 100644 --- a/entity-store/src/main/java/jetbrains/exodus/entitystore/iterate/EntityIdArrayCachedInstanceIterable.java +++ b/entity-store/src/main/java/jetbrains/exodus/entitystore/iterate/EntityIdArrayCachedInstanceIterable.java @@ -194,7 +194,7 @@ public EntityIdArrayCachedInstanceIterable(@NotNull final PersistentStoreTransac @Override public int getEntityTypeId() { - if (singleTypeId) { + if (singleTypeId && typeIds.length > 0) { return typeIds[0]; } return super.getEntityTypeId(); From 803f267b88e39996320c125033cfe943c50a52cb Mon Sep 17 00:00:00 2001 From: Vyacheslav Lukianov Date: Fri, 22 Jul 2016 17:32:58 +0300 Subject: [PATCH 2/2] got rid of fairness() --- .../ReentrantTransactionDispatcherTest.java | 46 ------------------- 1 file changed, 46 deletions(-) diff --git a/environment/src/test/java/jetbrains/exodus/env/ReentrantTransactionDispatcherTest.java b/environment/src/test/java/jetbrains/exodus/env/ReentrantTransactionDispatcherTest.java index ac4e222c8..c83ad2d32 100644 --- a/environment/src/test/java/jetbrains/exodus/env/ReentrantTransactionDispatcherTest.java +++ b/environment/src/test/java/jetbrains/exodus/env/ReentrantTransactionDispatcherTest.java @@ -16,7 +16,6 @@ package jetbrains.exodus.env; import jetbrains.exodus.ExodusException; -import jetbrains.exodus.core.execution.locks.Latch; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -73,49 +72,4 @@ public void downgrade() { dispatcher.downgradeTransaction(Thread.currentThread(), 2); Assert.assertEquals(9, dispatcher.getAvailablePermits()); } - - - @Test - public void fairness() throws InterruptedException { - final int maxTransactions = 20; - final ReentrantTransactionDispatcher dispatcher = new ReentrantTransactionDispatcher(maxTransactions); - dispatcher.acquireTransaction(Thread.currentThread()); - dispatcher.acquireTransaction(Thread.currentThread()); - final Latch latch = Latch.create(); - final int[] count = {0}; - latch.acquire(); - final Thread anotherExclusiveThread = new Thread(new Runnable() { - @Override - public void run() { - latch.release(); - final Thread thread = Thread.currentThread(); - final int permits = dispatcher.acquireExclusiveTransaction(thread); - Assert.assertEquals(maxTransactions, permits); - Assert.assertEquals(0, dispatcher.getAvailablePermits()); - Assert.assertEquals(0, count[0]); - dispatcher.releaseTransaction(thread, maxTransactions); - } - }); - anotherExclusiveThread.start(); - latch.acquire(); - for (int i = 0; i < maxTransactions; ++i) { - final int ii = i; - new Thread(new Runnable() { - @Override - public void run() { - latch.release(); - final Thread thread = Thread.currentThread(); - dispatcher.acquireTransaction(thread); - Assert.assertEquals(count[0]++, ii); - dispatcher.releaseTransaction(thread, 1); - } - }).start(); - latch.acquire(); - } - dispatcher.releaseTransaction(Thread.currentThread(), 1); - dispatcher.releaseTransaction(Thread.currentThread(), 1); - anotherExclusiveThread.join(); - Thread.sleep(1000); - Assert.assertEquals(maxTransactions, dispatcher.getAvailablePermits()); - } }