Skip to content

Commit

Permalink
Merge branch 'youtrack-7.0-hub-2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
penemue committed Jul 22, 2016
2 parents bf0660d + 803f267 commit 8f4e82b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 8f4e82b

Please sign in to comment.