mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't lose submitted transactions
This commit is contained in:
@@ -60,6 +60,7 @@ public class TransactionGuardImpl extends TransactionGuard {
|
||||
public void finish() {
|
||||
Queue<Transaction> queue = getQueue(prevTransaction);
|
||||
queue.addAll(myCurrentTransaction.myQueue);
|
||||
myCurrentTransaction.myQueue = queue;
|
||||
if (!queue.isEmpty()) {
|
||||
pollQueueLater();
|
||||
}
|
||||
@@ -72,14 +73,7 @@ public class TransactionGuardImpl extends TransactionGuard {
|
||||
|
||||
@NotNull
|
||||
private Queue<Transaction> getQueue(@Nullable TransactionIdImpl transaction) {
|
||||
if (transaction == null) {
|
||||
return myQueue;
|
||||
}
|
||||
if (myCurrentTransaction != null && transaction.myStartCounter > myCurrentTransaction.myStartCounter) {
|
||||
// transaction is finished already, it makes no sense to add to its queue
|
||||
return myCurrentTransaction.myQueue;
|
||||
}
|
||||
return transaction.myQueue;
|
||||
return transaction == null ? myQueue : transaction.myQueue;
|
||||
}
|
||||
|
||||
private void pollQueueLater() {
|
||||
@@ -304,7 +298,7 @@ public class TransactionGuardImpl extends TransactionGuard {
|
||||
private static class TransactionIdImpl implements TransactionId {
|
||||
private static final AtomicLong ourTransactionCounter = new AtomicLong();
|
||||
final long myStartCounter = ourTransactionCounter.getAndIncrement();
|
||||
final Queue<Transaction> myQueue = new LinkedBlockingQueue<Transaction>();
|
||||
Queue<Transaction> myQueue = new LinkedBlockingQueue<Transaction>();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -216,4 +216,18 @@ class TransactionTest extends LightPlatformTestCase {
|
||||
assert log == ['1', '2', '3', '4', '5']
|
||||
}
|
||||
|
||||
public void "test don't add transaction to outdated queue"() {
|
||||
TransactionGuard.submitTransaction testRootDisposable, {
|
||||
log << '1'
|
||||
guard.submitTransactionLater testRootDisposable, { log << '3' }
|
||||
log << '2'
|
||||
}
|
||||
TransactionGuard.submitTransaction testRootDisposable, {
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
assert log == ['1', '2']
|
||||
}
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
assert log == ['1', '2', '3']
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user