Refactor viewer sessions and selections and optimize transaction queries

This commit is contained in:
eyck committed 2026-11-15 10:08:36 +01:00
1 parent 4824d48828
commit 589762b220
42 files changed
+1118 -720

No files matched your search

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@@ -1,11 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.compiler.source=17
@@ -20,6 +20,25 @@ public class SQLiteBatchTest {
@Override public Connection createConnection() throws SQLException { connections++;return super.createConnection(); }
}
@Test
public void concurrentAttributeReadersShareOneCompletedLoad() throws Exception {
Database database = new Database();
ScvStream row = new ScvStream(); row.setId(1); row.setName("test"); row.setKind("test");
TxStream stream = new TxStream(database, row);
ITx transaction = stream.getTransactionList().get(0);
int before = database.connections;
java.util.concurrent.ExecutorService workers = java.util.concurrent.Executors.newFixedThreadPool(8);
java.util.concurrent.CountDownLatch start = new java.util.concurrent.CountDownLatch(1);
try {
java.util.List<java.util.concurrent.Future<java.util.List<com.minres.scviewer.database.tx.ITxAttribute>>> results = new java.util.ArrayList<>();
for (int i = 0; i < 8; i++) results.add(workers.submit(() -> { start.await(); return transaction.getAttributes(); }));
start.countDown();
java.util.List<com.minres.scviewer.database.tx.ITxAttribute> attributes = results.get(0).get(5, java.util.concurrent.TimeUnit.SECONDS);
for (java.util.concurrent.Future<?> result : results) assertSame(attributes, result.get(5, java.util.concurrent.TimeUnit.SECONDS));
assertEquals(before + 1, database.connections);
} finally { workers.shutdownNow(); }
}
@Test
public void loadsAllTimesInOneQueryAndSharesGeneratorTransactions() {
Database database = new Database();
@@ -0,0 +1,53 @@
package com.minres.scviewer.database.test;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Test;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDbLoader;
import com.minres.scviewer.database.ftr.FtrDbLoader;
import com.minres.scviewer.database.text.TextDbLoader;
import com.minres.scviewer.database.sqlite.SQLiteDbLoader;
import com.minres.scviewer.database.tx.ITx;
import com.minres.scviewer.database.tx.ITransactionProvider;
public class TransactionIndexTest {
@Test
public void transactionListsAreCachedAndLookupsRespectGeneratorMembership() throws Exception {
IWaveformDbLoader[] loaders = {new FtrDbLoader(), new TextDbLoader(), new SQLiteDbLoader()};
String[] inputs = {"my_db.ftr", "my_db.txlog", "my_sqldb.txdb"};
for (int i = 0; i < loaders.length; i++) {
IWaveformDbLoader loader = loaders[i];
try {
loader.load(TxTestSupport.input(inputs[i]));
for (IWaveform wave : loader.getAllWaves()) {
if (!wave.getType().isTransaction()) continue;
assertTrue(wave instanceof ITransactionProvider);
check((ITransactionProvider) wave);
for (com.minres.scviewer.database.IHierNode child : wave.getChildNodes()) {
if (!(child instanceof ITransactionProvider generator)) continue;
check(generator);
for (ITx transaction : ((ITransactionProvider) wave).getTransactionList())
if (transaction.getGenerator() != child) assertNull(generator.getTransaction(transaction.getId()));
}
}
} finally { loader.dispose(); }
}
}
private void check(ITransactionProvider provider) {
List<ITx> transactions = provider.getTransactionList();
assertSame(transactions, provider.getTransactionList());
for (int i = 0; i < transactions.size(); i++) {
ITx transaction = transactions.get(i);
assertSame(transaction, provider.getTransaction(transaction.getId()));
if (i > 0) assertTrue(transactions.get(i - 1).compareTo(transaction) <= 0);
}
assertNull(provider.getTransaction(Long.MAX_VALUE));
try { transactions.clear(); fail("Index list must be immutable"); }
catch (UnsupportedOperationException expected) {}
}
}