applies concurrency fixes
This commit is contained in:
1 parent
42e0d83403
commit
28eb1b673e
56 files changed
+1462
-372
No files matched your search
+12
@@ -45,6 +45,18 @@ public class CombinedBitVectorTest {
|
||||
}
|
||||
private String value(EventEntry entry) { return entry == null ? null : entry.events[0].toString(); }
|
||||
|
||||
@Test public void cancellationStopsAnUnchangedHistoryScanAndAllowsRetry() {
|
||||
var input = new Signal(0, "input", 2);
|
||||
for (int i = 0; i < 1000; i++) input.addSignalChange(i, BitVector.fromString(2, i % 2 == 0 ? "00" : "10"));
|
||||
var bus = combine(input, input);
|
||||
AtomicInteger checks = new AtomicInteger();
|
||||
try {
|
||||
ReadCancellation.with(() -> checks.incrementAndGet() > 30, () -> bus.getEvents().floorEntry(999));
|
||||
fail("History scan ignored cancellation");
|
||||
} catch (java.util.concurrent.CancellationException expected) { }
|
||||
assertEquals(0, bus.getEvents().floorEntry(999).timestamp);
|
||||
}
|
||||
|
||||
@Test public void mergesStaggeredAndSimultaneousChangesAndSuppressesUnchangedValues() {
|
||||
var a = signal("a", new long[]{5, 20, 20, 25, 30, 40}, "0", "0", "1", "1", "x", "z");
|
||||
var b = signal("b", new long[]{10, 20, 25}, "1", "0", "0");
|
||||
|
||||
+45
@@ -49,6 +49,51 @@ public class SQLiteBatchTest {
|
||||
} finally { workers.shutdownNow(); }
|
||||
}
|
||||
|
||||
@Test public void relationReadersWaitForCompletedInitialization() throws Exception {
|
||||
var entered = new java.util.concurrent.CountDownLatch(1);
|
||||
var release = new java.util.concurrent.CountDownLatch(1);
|
||||
var recording = java.nio.file.Files.createTempFile("scviewer-relations-", ".txdb");
|
||||
java.nio.file.Files.copy(TxTestSupport.input("my_sqldb.txdb").toPath(), recording, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
class BlockingDatabase extends Database {
|
||||
volatile boolean block;
|
||||
@Override public String getConnectionUrl() { return "jdbc:sqlite:" + recording; }
|
||||
@Override public Connection createConnection() throws SQLException {
|
||||
if (block) {
|
||||
entered.countDown();
|
||||
try { assertTrue(release.await(5, java.util.concurrent.TimeUnit.SECONDS)); }
|
||||
catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new SQLException(e); }
|
||||
}
|
||||
return super.createConnection();
|
||||
}
|
||||
}
|
||||
BlockingDatabase database = new BlockingDatabase();
|
||||
ScvStream row = new ScvStream(); row.setId(1); row.setName("test"); row.setKind("test");
|
||||
TxStream stream = new TxStream(database, row);
|
||||
try (Connection connection = database.createConnection(); var statement = connection.createStatement()) {
|
||||
statement.executeUpdate("DELETE FROM ScvTxRelation");
|
||||
}
|
||||
ITx transaction = stream.getTransactionList().get(0);
|
||||
int before = database.connections;
|
||||
database.block = true;
|
||||
var workers = java.util.concurrent.Executors.newFixedThreadPool(2);
|
||||
try {
|
||||
var first = workers.submit(transaction::getIncomingRelations);
|
||||
assertTrue(entered.await(5, java.util.concurrent.TimeUnit.SECONDS));
|
||||
var secondStarted = new java.util.concurrent.CountDownLatch(1);
|
||||
var second = workers.submit(() -> { secondStarted.countDown(); return transaction.getIncomingRelations(); });
|
||||
assertTrue(secondStarted.await(5, java.util.concurrent.TimeUnit.SECONDS));
|
||||
try { second.get(100, java.util.concurrent.TimeUnit.MILLISECONDS); fail("Published an unfinished relation list"); }
|
||||
catch (java.util.concurrent.TimeoutException expected) { }
|
||||
release.countDown();
|
||||
assertTrue(first.get(5, java.util.concurrent.TimeUnit.SECONDS).isEmpty());
|
||||
assertTrue(second.get(5, java.util.concurrent.TimeUnit.SECONDS).isEmpty());
|
||||
assertEquals(before + 1, database.connections);
|
||||
} finally {
|
||||
release.countDown(); workers.shutdownNow();
|
||||
java.nio.file.Files.deleteIfExists(recording);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadsAllTimesInOneQueryAndSharesGeneratorTransactions() {
|
||||
Database database = new Database();
|
||||
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2026 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import org.junit.Test;
|
||||
import com.minres.scviewer.database.*;
|
||||
|
||||
public class ThreadingTest {
|
||||
@Test public void registryPublishesEveryNameAndOneIdentity() throws Exception {
|
||||
String prefix = UUID.randomUUID().toString();
|
||||
ExecutorService pool = Executors.newFixedThreadPool(8);
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
try {
|
||||
List<Future<List<RelationType>>> results = new ArrayList<>();
|
||||
for (int thread = 0; thread < 8; thread++) {
|
||||
int id = thread;
|
||||
results.add(pool.submit(() -> {
|
||||
start.await();
|
||||
List<RelationType> values = new ArrayList<>();
|
||||
for (int i = 0; i < 2000; i++) {
|
||||
values.add(RelationTypeFactory.create(prefix + ":" + id + ":" + i));
|
||||
assertSame(RelationTypeFactory.create(prefix), RelationTypeFactory.create(prefix));
|
||||
}
|
||||
return values;
|
||||
}));
|
||||
}
|
||||
start.countDown();
|
||||
for (int thread = 0; thread < results.size(); thread++) {
|
||||
List<RelationType> values = results.get(thread).get(10, TimeUnit.SECONDS);
|
||||
for (int i = 0; i < values.size(); i++) assertSame(values.get(i), RelationTypeFactory.create(prefix + ":" + thread + ":" + i));
|
||||
}
|
||||
} finally { pool.shutdownNow(); }
|
||||
}
|
||||
|
||||
@Test public void hierarchyReturnsStableSnapshotsWithInitializedParents() {
|
||||
HierNode root = new HierNode("root");
|
||||
HierNode first = new HierNode("first");
|
||||
root.addChild(first);
|
||||
List<IHierNode> snapshot = root.getChildNodes();
|
||||
root.addChild(new HierNode("second"));
|
||||
assertEquals(List.of(first), snapshot);
|
||||
assertSame(root, snapshot.get(0).getParent());
|
||||
assertEquals(2, root.getChildNodes().size());
|
||||
}
|
||||
|
||||
@Test public void closureWaitsForReadersAndRejectsStaleReferences() throws Exception {
|
||||
WaveformAccess.Scope scope = new WaveformAccess.Scope();
|
||||
EmptyWaveform wave = new EmptyWaveform("wave");
|
||||
scope.register(List.of(wave));
|
||||
CountDownLatch entered = new CountDownLatch(1), release = new CountDownLatch(1);
|
||||
AtomicBoolean disposed = new AtomicBoolean();
|
||||
ExecutorService pool = Executors.newFixedThreadPool(3);
|
||||
try {
|
||||
Future<?> reader = pool.submit(() -> WaveformAccess.read(wave, () -> {
|
||||
entered.countDown();
|
||||
try { assertTrue(release.await(5, TimeUnit.SECONDS)); }
|
||||
catch (InterruptedException e) { throw new AssertionError(e); }
|
||||
assertFalse(disposed.get());
|
||||
return null;
|
||||
}));
|
||||
assertTrue(entered.await(5, TimeUnit.SECONDS));
|
||||
CountDownLatch closing = new CountDownLatch(1);
|
||||
Future<?> close = pool.submit(() -> { closing.countDown(); scope.close(() -> disposed.set(true)); });
|
||||
assertTrue(closing.await(5, TimeUnit.SECONDS));
|
||||
Future<?> rejected = pool.submit(() -> {
|
||||
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5);
|
||||
while (System.nanoTime() < deadline) {
|
||||
try { WaveformAccess.read(wave, () -> null); }
|
||||
catch (CancellationException expected) { return; }
|
||||
Thread.yield();
|
||||
}
|
||||
fail("New readers were admitted during closure");
|
||||
});
|
||||
rejected.get(5, TimeUnit.SECONDS);
|
||||
assertFalse(disposed.get());
|
||||
release.countDown();
|
||||
reader.get(5, TimeUnit.SECONDS); close.get(5, TimeUnit.SECONDS);
|
||||
assertTrue(disposed.get());
|
||||
try { WaveformAccess.read(wave, () -> null); fail("Read a closed recording"); }
|
||||
catch (CancellationException expected) { }
|
||||
} finally { release.countDown(); pool.shutdownNow(); }
|
||||
}
|
||||
|
||||
@Test public void cancelledLazyInitializationCanRetry() {
|
||||
LazyValue<String> value = new LazyValue<>();
|
||||
try { value.get(() -> { throw new CancellationException(); }); fail(); }
|
||||
catch (CancellationException expected) { }
|
||||
assertEquals("complete", value.get(() -> "complete"));
|
||||
}
|
||||
|
||||
@Test public void lazyWaiterCancelsWithoutBlockingOrCancellingOwner() throws Exception {
|
||||
LazyValue<String> value = new LazyValue<>();
|
||||
ExecutorService pool = Executors.newFixedThreadPool(2);
|
||||
CountDownLatch entered = new CountDownLatch(1), release = new CountDownLatch(1);
|
||||
AtomicBoolean cancelled = new AtomicBoolean();
|
||||
CountDownLatch waiterWaiting = new CountDownLatch(1);
|
||||
java.util.concurrent.atomic.AtomicInteger checks = new java.util.concurrent.atomic.AtomicInteger();
|
||||
try {
|
||||
Future<String> owner = pool.submit(() -> value.get(() -> {
|
||||
entered.countDown();
|
||||
try { assertTrue(release.await(5, TimeUnit.SECONDS)); }
|
||||
catch (InterruptedException e) { throw new AssertionError(e); }
|
||||
return "complete";
|
||||
}));
|
||||
assertTrue(entered.await(5, TimeUnit.SECONDS));
|
||||
Future<String> waiter = pool.submit(() -> ReadCancellation.with(() -> {
|
||||
if (checks.incrementAndGet() >= 2) waiterWaiting.countDown();
|
||||
return cancelled.get();
|
||||
}, () -> value.get(() -> "wrong")));
|
||||
assertTrue("Waiter never reached cancellable lazy wait", waiterWaiting.await(5, TimeUnit.SECONDS));
|
||||
cancelled.set(true);
|
||||
try { waiter.get(2, TimeUnit.SECONDS); fail(); }
|
||||
catch (ExecutionException expected) { assertTrue(expected.getCause() instanceof CancellationException); }
|
||||
assertFalse(owner.isDone());
|
||||
release.countDown();
|
||||
assertEquals("complete", owner.get(5, TimeUnit.SECONDS));
|
||||
} finally { release.countDown(); pool.shutdownNow(); }
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2026 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application.internal.status;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JobProgressTest {
|
||||
@Test public void cancellationAndProgressBelongToOneJob() {
|
||||
JobProgress first = new JobProgress(() -> {}), second = new JobProgress(() -> {});
|
||||
first.beginTask("first", 10); second.beginTask("second", 20);
|
||||
first.worked(3); second.worked(8); first.setCanceled(true); first.done();
|
||||
assertTrue(first.isCanceled()); assertFalse(second.isCanceled());
|
||||
assertTrue(first.snapshot().done()); assertFalse(second.snapshot().done());
|
||||
assertEquals("second", second.snapshot().name());
|
||||
assertEquals(8, second.snapshot().work(), 0);
|
||||
assertFalse(new JobProgress(() -> {}).isCanceled());
|
||||
}
|
||||
}
|
||||
+34
@@ -70,4 +70,38 @@ public class LatestJobTest {
|
||||
query.schedule("closed", monitor -> { fail("Disposed query must not run"); return ""; });
|
||||
assertTrue(displayed.isEmpty());
|
||||
}
|
||||
|
||||
@Test public void additiveRequestsBothPublishAndCloseDiscardsQueuedResults() throws Exception {
|
||||
BlockingQueue<Runnable> ui = new LinkedBlockingQueue<>();
|
||||
List<String> displayed = new ArrayList<>();
|
||||
try (LatestJob<String> jobs = new LatestJob<>(ui::add, displayed::add, false)) {
|
||||
jobs.schedule("first vector", monitor -> "first");
|
||||
Runnable first = take(ui);
|
||||
jobs.schedule("second vector", monitor -> "second");
|
||||
Runnable second = take(ui);
|
||||
first.run(); second.run();
|
||||
assertEquals(List.of("first", "second"), displayed);
|
||||
jobs.schedule("stale", monitor -> "stale");
|
||||
Runnable stale = take(ui);
|
||||
jobs.cancel(); stale.run();
|
||||
assertEquals(2, displayed.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void cancellingJobReachesNestedReadContext() throws Exception {
|
||||
BlockingQueue<Runnable> ui = new LinkedBlockingQueue<>();
|
||||
java.util.concurrent.CountDownLatch entered = new java.util.concurrent.CountDownLatch(1);
|
||||
java.util.concurrent.CountDownLatch stopped = new java.util.concurrent.CountDownLatch(1);
|
||||
try (LatestJob<String> query = new LatestJob<>(ui::add, ignored -> fail("Cancelled job published"))) {
|
||||
query.schedule("long read", monitor -> {
|
||||
entered.countDown();
|
||||
try { while (true) com.minres.scviewer.database.ReadCancellation.check(); }
|
||||
finally { stopped.countDown(); }
|
||||
});
|
||||
assertTrue(entered.await(5, TimeUnit.SECONDS));
|
||||
query.cancel();
|
||||
assertTrue(stopped.await(5, TimeUnit.SECONDS));
|
||||
assertTrue(ui.isEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -125,4 +125,29 @@ public class TransactionQueryTest {
|
||||
assertEquals(0, reads.get());
|
||||
assertEquals(0, wave.requests);
|
||||
}
|
||||
|
||||
@Test public void slowPropertyDiscoveryDoesNotBlockHeaderRequests() throws Exception {
|
||||
var entered = new java.util.concurrent.CountDownLatch(1);
|
||||
var release = new java.util.concurrent.CountDownLatch(1);
|
||||
Waveform wave = new Waveform();
|
||||
ITx slow = (ITx) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[]{ITx.class}, (p, m, a) -> {
|
||||
if (m.getName().equals("getAttributes")) {
|
||||
entered.countDown();
|
||||
assertTrue(release.await(5, java.util.concurrent.TimeUnit.SECONDS));
|
||||
return List.of();
|
||||
}
|
||||
return 1L;
|
||||
});
|
||||
wave.transactions = List.of(slow);
|
||||
TransactionQuery query = new TransactionQuery(wave);
|
||||
var workers = java.util.concurrent.Executors.newFixedThreadPool(2);
|
||||
try {
|
||||
var discovery = workers.submit(() -> query.discoverAttributes(() -> false));
|
||||
assertTrue(entered.await(5, java.util.concurrent.TimeUnit.SECONDS));
|
||||
assertSame(wave.transactions, workers.submit(() -> query.transactions(() -> false))
|
||||
.get(1, java.util.concurrent.TimeUnit.SECONDS));
|
||||
release.countDown();
|
||||
assertTrue(discovery.get(5, java.util.concurrent.TimeUnit.SECONDS).isEmpty());
|
||||
} finally { release.countDown(); workers.shutdownNow(); }
|
||||
}
|
||||
}
|
||||
+13
-3
@@ -113,12 +113,12 @@ public class BitVectorExpansionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void realScalarAndEmptySignalsCannotBeExpanded() {
|
||||
Signal real = new Signal("real", 64);
|
||||
public void realAndScalarSignalsCannotBeExpanded() {
|
||||
Signal real = new Signal("real", 64) { @Override public boolean isBitVector() { return false; } };
|
||||
real.events.put(0, new DoubleVal(1.5));
|
||||
Signal scalar = new Signal("scalar", 1);
|
||||
scalar.events.put(0, BitVector.fromString(1, "1"));
|
||||
for (Signal source : List.of(real, scalar, new Signal("empty", 8))) {
|
||||
for (Signal source : List.of(real, scalar)) {
|
||||
TrackEntry track = new TrackEntry(source, null);
|
||||
track.setExpanded(true);
|
||||
assertFalse(track.isExpandable());
|
||||
@@ -127,6 +127,16 @@ public class BitVectorExpansionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void vectorMetadataDoesNotReadEventsOnTheUiThread() {
|
||||
Signal source = new Signal("lazy", 8) {
|
||||
@Override public IEventList getEvents() { throw new AssertionError("Metadata triggered I/O"); }
|
||||
};
|
||||
TrackEntry track = new TrackEntry(source, null);
|
||||
assertTrue(track.isExpandable());
|
||||
track.setExpanded(true);
|
||||
assertEquals(8, track.waveforms.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void savedExpansionPreservesHiddenBitsAndResolvesProjectedNames() throws Exception {
|
||||
Signal source = new Signal("top.bus[3:0]", 4);
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ public class CombinedVectorSettingsTest {
|
||||
assertTrue(BitVectorComposition.selectedBits(roots, List.of(bus, first)).isEmpty());
|
||||
assertTrue(BitVectorComposition.selectedBits(roots, List.of(first)).isEmpty());
|
||||
assertTrue(BitVectorComposition.selectedBits(roots, List.of(first, new TrackEntry(input, null))).isEmpty());
|
||||
var real = new BitVectorExpansionTest.Signal("real", 1);
|
||||
var real = new BitVectorExpansionTest.Signal("real", 1) { @Override public boolean isBitVector() { return false; } };
|
||||
real.events.put(0, new DoubleVal(1.0));
|
||||
assertFalse(BitVectorComposition.isSingleBit(new TrackEntry(real, null)));
|
||||
var sources = BitVectorComposition.sources(List.of(second, first));
|
||||
|
||||
+14
-1
@@ -112,7 +112,10 @@ public class TransactionListPropertiesTest {
|
||||
case "getId" -> id;
|
||||
case "getBeginTime" -> 0L;
|
||||
case "getEndTime" -> 1L;
|
||||
case "getAttributes" -> List.of(attributes);
|
||||
case "getAttributes" -> {
|
||||
assertNull("A label callback read attributes on SWT", Display.getCurrent());
|
||||
yield List.of(attributes);
|
||||
}
|
||||
case "hashCode" -> System.identityHashCode(p);
|
||||
case "equals" -> p == a[0];
|
||||
case "toString" -> "tx#" + id;
|
||||
@@ -136,6 +139,7 @@ public class TransactionListPropertiesTest {
|
||||
await(() -> shown.getItemCount() == 2 && table.getItemCount() == 1);
|
||||
assertEquals("late [STRING]", search.getText());
|
||||
assertEquals("late [STRING]", shown.getText());
|
||||
await(() -> "last".equals(table.getItem(0).getText(2)));
|
||||
assertEquals("last", table.getItem(0).getText(2));
|
||||
}
|
||||
|
||||
@@ -145,6 +149,7 @@ public class TransactionListPropertiesTest {
|
||||
await(() -> shown.getSelectionIndex() >= 0 && table.getItemCount() == 1);
|
||||
assertEquals("address [STRING]", shown.getText());
|
||||
assertEquals("address [STRING]", search.getText());
|
||||
await(() -> "value".equals(table.getItem(0).getText(2)));
|
||||
assertEquals("value", table.getItem(0).getText(2));
|
||||
}
|
||||
|
||||
@@ -156,6 +161,7 @@ public class TransactionListPropertiesTest {
|
||||
input(transactions.toArray(new ITx[0]));
|
||||
await(() -> shown.getItemCount() == 3 && table.getItemCount() == 33);
|
||||
shown.select(1); shown.notifyListeners(SWT.Selection, new Event());
|
||||
await(() -> "second".equals(table.getItem(0).getText(2)));
|
||||
assertEquals("second", table.getItem(0).getText(2));
|
||||
assertTrue(Arrays.asList(shown.getItems()).contains("late [STRING]"));
|
||||
list.setVisible(false);
|
||||
@@ -169,22 +175,26 @@ public class TransactionListPropertiesTest {
|
||||
input(transaction(1, attribute("alpha", "first"), attribute("beta", "chosen")));
|
||||
await(() -> shown.getItemCount() == 2 && table.getItemCount() == 1);
|
||||
shown.select(1); shown.notifyListeners(SWT.Selection, new Event());
|
||||
await(() -> "chosen".equals(table.getItem(0).getText(2)));
|
||||
assertEquals("chosen", table.getItem(0).getText(2));
|
||||
|
||||
// The preferred property is no longer the second entry in the new stream.
|
||||
input(transaction(2, attribute("aardvark", "a"), attribute("alpha", "b"), attribute("beta", "restored")));
|
||||
await(() -> shown.getItemCount() == 3 && table.getItemCount() == 1);
|
||||
assertEquals("beta [STRING]", shown.getText());
|
||||
await(() -> "restored".equals(table.getItem(0).getText(2)));
|
||||
assertEquals("restored", table.getItem(0).getText(2));
|
||||
|
||||
// A temporary fallback and a separator must not erase the user's preference.
|
||||
input(transaction(3, attribute("other", "fallback")));
|
||||
await(() -> shown.getText().equals("other [STRING]") && table.getItemCount() == 1);
|
||||
await(() -> "fallback".equals(table.getItem(0).getText(2)));
|
||||
assertEquals("fallback", table.getItem(0).getText(2));
|
||||
listView.setSelection(new StructuredSelection(new TrackEntry(new EmptyWaveform(), null)));
|
||||
input(transaction(4, attribute("alpha", "default"), attribute("beta", "remembered")));
|
||||
await(() -> shown.getItemCount() == 2 && table.getItemCount() == 1);
|
||||
assertEquals("beta [STRING]", shown.getText());
|
||||
await(() -> "remembered".equals(table.getItem(0).getText(2)));
|
||||
assertEquals("remembered", table.getItem(0).getText(2));
|
||||
|
||||
// A subsequent explicit choice replaces the remembered preference.
|
||||
@@ -192,6 +202,7 @@ public class TransactionListPropertiesTest {
|
||||
input(transaction(5, attribute("aardvark", "default"), attribute("alpha", "new preference"), attribute("beta", "old")));
|
||||
await(() -> shown.getItemCount() == 3 && table.getItemCount() == 1);
|
||||
assertEquals("alpha [STRING]", shown.getText());
|
||||
await(() -> "new preference".equals(table.getItem(0).getText(2)));
|
||||
assertEquals("new preference", table.getItem(0).getText(2));
|
||||
}
|
||||
|
||||
@@ -209,6 +220,7 @@ public class TransactionListPropertiesTest {
|
||||
list.setVisible(true);
|
||||
await(() -> shown.getItemCount() == 1 && table.getItemCount() == 1);
|
||||
assertEquals("address [STRING]", shown.getText());
|
||||
await(() -> "value".equals(table.getItem(0).getText(2)));
|
||||
assertEquals("value", table.getItem(0).getText(2));
|
||||
}
|
||||
|
||||
@@ -217,6 +229,7 @@ public class TransactionListPropertiesTest {
|
||||
input(transaction(1, attribute("old", "old value")));
|
||||
input(transaction(2, attribute("new", "new value")));
|
||||
await(() -> shown.getText().equals("new [STRING]") && table.getItemCount() == 1);
|
||||
await(() -> "new value".equals(table.getItem(0).getText(2)));
|
||||
assertEquals("new value", table.getItem(0).getText(2));
|
||||
listView.setSelection(new StructuredSelection(new TrackEntry(new EmptyWaveform(), null)));
|
||||
assertEquals(0, shown.getItemCount());
|
||||
|
||||
+49
-1
@@ -176,6 +176,7 @@ public class WaveformScrollTest {
|
||||
assertSame(bus, ((StructuredSelection) view.getSelection()).getFirstElement());
|
||||
view.setGroupExpanded(bus, true);
|
||||
assertEquals(6, TrackEntry.visibleTracks(view.getStreamList()).size());
|
||||
waitUntil(() -> "b'1".equals(bus.waveforms.get(0).currentValue) && "b'0".equals(bus.waveforms.get(1).currentValue));
|
||||
assertEquals("b'1", bus.waveforms.get(0).currentValue);
|
||||
assertEquals("b'0", bus.waveforms.get(1).currentValue);
|
||||
view.setGroupExpanded(bus, false);
|
||||
@@ -270,8 +271,53 @@ public class WaveformScrollTest {
|
||||
} finally { if (dialog.getShell() != null && !dialog.getShell().isDisposed()) dialog.close(); }
|
||||
}
|
||||
|
||||
@Test public void lazySignalReadsStayOffSwtAndQueuedUpdatesSurviveDisposal() throws Exception {
|
||||
var reads = new java.util.concurrent.atomic.AtomicInteger();
|
||||
var source = new BitVectorExpansionTest.Signal("lazy", 4) {
|
||||
@Override public com.minres.scviewer.database.IEventList getEvents() {
|
||||
assertNull("Lazy signal read on SWT", Display.getCurrent());
|
||||
reads.incrementAndGet();
|
||||
return events;
|
||||
}
|
||||
};
|
||||
source.events.put(0, com.minres.scviewer.database.BitVector.fromString(4, "1010"));
|
||||
TrackEntry track = view.addWaveform(source, -1);
|
||||
view.setCursorTime(0); view.update();
|
||||
waitUntil(() -> !track.currentValue.equals("---") && reads.get() > 0);
|
||||
invokeView("asyncUpdate", new Class<?>[]{org.eclipse.swt.widgets.Widget.class}, canvas);
|
||||
shell.dispose();
|
||||
drainEvents();
|
||||
}
|
||||
|
||||
@Test public void disposingPressedImageButtonStopsItsRepeatTimer() throws Exception {
|
||||
Class<?> type = view.getClass().getClassLoader().loadClass(
|
||||
"com.minres.scviewer.database.ui.swt.internal.slider.ImageButton");
|
||||
var button = (org.eclipse.swt.widgets.Composite) type.getConstructor(org.eclipse.swt.widgets.Composite.class, int.class)
|
||||
.newInstance(shell, SWT.NONE);
|
||||
type.getMethod("setAutoFire", boolean.class).invoke(button, true);
|
||||
button.notifyListeners(SWT.MouseDown, new Event());
|
||||
var field = type.getDeclaredField("actionTimer"); field.setAccessible(true);
|
||||
Runnable timer = (Runnable) field.get(button);
|
||||
button.dispose();
|
||||
timer.run();
|
||||
drainEvents();
|
||||
}
|
||||
|
||||
@Test public void twoRapidCombineCommandsBothCreateVectors() throws Exception {
|
||||
var inputs = scalarInputs();
|
||||
WaveformViewer viewer = compositionViewer(display::asyncExec);
|
||||
try {
|
||||
viewer.combineBits("first", inputs);
|
||||
viewer.combineBits("second", inputs);
|
||||
waitUntil(() -> view.getStreamList().size() == 4);
|
||||
assertEquals(java.util.Set.of("first", "second"), view.getStreamList().stream()
|
||||
.filter(track -> track.waveform instanceof com.minres.scviewer.database.CombinedBitVectorWaveform)
|
||||
.map(track -> track.waveform.getDisplayName()).collect(java.util.stream.Collectors.toSet()));
|
||||
} finally { viewer.closeDatabase(); }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bitvectorDisclosureUpdatesAllPanesAndCursorValues() {
|
||||
public void bitvectorDisclosureUpdatesAllPanesAndCursorValues() throws Exception {
|
||||
var source = new BitVectorExpansionTest.Signal("bus", 4);
|
||||
source.events.put(10, com.minres.scviewer.database.BitVector.fromString(4, "10xz"));
|
||||
source.events.put(20, com.minres.scviewer.database.BitVector.fromString(4, "0011"));
|
||||
@@ -287,10 +333,12 @@ public class WaveformScrollTest {
|
||||
view.getNameControl().notifyListeners(SWT.MouseUp, event);
|
||||
drainEvents();
|
||||
assertEquals(TrackEntry.HierState.OPENED, bus.hierState);
|
||||
waitUntil(() -> bus.waveforms.stream().map(track -> track.currentValue).toList().equals(List.of("b'1", "b'0", "b'x", "b'z")));
|
||||
assertEquals(List.of("b'1", "b'0", "b'x", "b'z"),
|
||||
bus.waveforms.stream().map(track -> track.currentValue).toList());
|
||||
view.setCursorTime(20);
|
||||
view.update();
|
||||
waitUntil(() -> bus.waveforms.stream().map(track -> track.currentValue).toList().equals(List.of("b'0", "b'0", "b'1", "b'1")));
|
||||
assertEquals(List.of("b'0", "b'0", "b'1", "b'1"),
|
||||
bus.waveforms.stream().map(track -> track.currentValue).toList());
|
||||
view.getNameControl().notifyListeners(SWT.MouseUp, event);
|
||||
|
||||
Reference in new issue
Block a user