1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-19 01:42:52 +03:00

Minor reshaping of Tester1 moving towards making a multi-threaded run mode.

FossilOrigin-Name: f104c14c26c123ee78c09fc1bc59efb8668dc624da05c1d8dbeaf3c9dd02a393
This commit is contained in:
stephan
2023-08-15 09:26:47 +00:00
parent 9019e2e667
commit 6b51e35a9b
4 changed files with 42 additions and 25 deletions

View File

@ -141,7 +141,7 @@ public final class SQLite3Jni {
undefined if any database objects are (A) still active at the undefined if any database objects are (A) still active at the
time it is called _and_ (B) calls are subsequently made into the time it is called _and_ (B) calls are subsequently made into the
library with such a database. Doing so will, at best, lead to a library with such a database. Doing so will, at best, lead to a
crash. Azt worst, it will lead to the db possibly misbehaving crash. At worst, it will lead to the db possibly misbehaving
because some of its Java-bound state has been cleared. There is because some of its Java-bound state has been cleared. There is
no immediate harm in (A) so long as condition (B) is not met. no immediate harm in (A) so long as condition (B) is not met.
This process does _not_ actually close any databases or finalize This process does _not_ actually close any databases or finalize

View File

@ -21,6 +21,12 @@ public class Tester1 {
int dbOpen; int dbOpen;
} }
private String name;
Tester1(String name){
this.name = name;
}
static final Metrics metrics = new Metrics(); static final Metrics metrics = new Metrics();
private static final OutputPointer.sqlite3_stmt outStmt private static final OutputPointer.sqlite3_stmt outStmt
= new OutputPointer.sqlite3_stmt(); = new OutputPointer.sqlite3_stmt();
@ -45,11 +51,17 @@ public class Tester1 {
} }
static int affirmCount = 0; static int affirmCount = 0;
public static void affirm(Boolean v){ public static void affirm(Boolean v, String comment){
++affirmCount; ++affirmCount;
assert( v /* prefer assert over exception if it's enabled because assert( v /* prefer assert over exception if it's enabled because
the JNI layer sometimes has to suppress exceptions. */); the JNI layer sometimes has to suppress exceptions,
if( !v ) throw new RuntimeException("Assertion failed."); so they might be squelched on their way back to the
top. */);
if( !v ) throw new RuntimeException(comment);
}
public static void affirm(Boolean v){
affirm(v, "Affirmation failed.");
} }
private static void test1(){ private static void test1(){
@ -65,7 +77,7 @@ public class Tester1 {
affirm(SQLITE_MAX_TRIGGER_DEPTH>0); affirm(SQLITE_MAX_TRIGGER_DEPTH>0);
} }
public static sqlite3 createNewDb(){ static sqlite3 createNewDb(){
final OutputPointer.sqlite3 out = new OutputPointer.sqlite3(); final OutputPointer.sqlite3 out = new OutputPointer.sqlite3();
int rc = sqlite3_open(":memory:", out); int rc = sqlite3_open(":memory:", out);
++metrics.dbOpen; ++metrics.dbOpen;
@ -83,11 +95,11 @@ public class Tester1 {
return db; return db;
} }
public static void execSql(sqlite3 db, String[] sql){ static void execSql(sqlite3 db, String[] sql){
execSql(db, String.join("", sql)); execSql(db, String.join("", sql));
} }
public static int execSql(sqlite3 db, boolean throwOnError, String sql){ static int execSql(sqlite3 db, boolean throwOnError, String sql){
OutputPointer.Int32 oTail = new OutputPointer.Int32(); OutputPointer.Int32 oTail = new OutputPointer.Int32();
final byte[] sqlUtf8 = sql.getBytes(StandardCharsets.UTF_8); final byte[] sqlUtf8 = sql.getBytes(StandardCharsets.UTF_8);
int pos = 0, n = 1; int pos = 0, n = 1;
@ -127,11 +139,11 @@ public class Tester1 {
return rc; return rc;
} }
public static void execSql(sqlite3 db, String sql){ static void execSql(sqlite3 db, String sql){
execSql(db, true, sql); execSql(db, true, sql);
} }
public static sqlite3_stmt prepare(sqlite3 db, String sql){ static sqlite3_stmt prepare(sqlite3 db, String sql){
outStmt.clear(); outStmt.clear();
int rc = sqlite3_prepare(db, sql, outStmt); int rc = sqlite3_prepare(db, sql, outStmt);
affirm( 0 == rc ); affirm( 0 == rc );
@ -519,7 +531,6 @@ public class Tester1 {
rc = sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, cur32, high32, false); rc = sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, cur32, high32, false);
affirm( 0 == rc ); affirm( 0 == rc );
affirm( cur32.value > 0 ); affirm( cur32.value > 0 );
outln(cur32.value," ",high32.value);
affirm( high32.value == 0 /* always 0 for SCHEMA_USED */ ); affirm( high32.value == 0 /* always 0 for SCHEMA_USED */ );
sqlite3_close_v2(db); sqlite3_close_v2(db);
@ -1110,12 +1121,9 @@ public class Tester1 {
outln("Woke up."); outln("Woke up.");
} }
public static void main(String[] args) throws Exception { private void runTests() throws Exception {
final long timeStart = System.nanoTime();
test1();
if(false) testCompileOption(); if(false) testCompileOption();
final java.util.List<String> liArgs = test1();
java.util.Arrays.asList(args);
testOpenDb1(); testOpenDb1();
testOpenDb2(); testOpenDb2();
testPrepare123(); testPrepare123();
@ -1141,12 +1149,21 @@ public class Tester1 {
testAuthorizer(); testAuthorizer();
testFts5(); testFts5();
testAutoExtension(); testAutoExtension();
}
public static void main(String[] args) throws Exception {
final long timeStart = System.nanoTime();
new Tester1("main thread").runTests();
final long timeEnd = System.nanoTime();
final java.util.List<String> liArgs =
java.util.Arrays.asList(args);
//testSleep(); //testSleep();
if(liArgs.indexOf("-v")>0){ if(liArgs.indexOf("-v")>0){
sqlite3_do_something_for_developer(); sqlite3_do_something_for_developer();
//listBoundMethods(); //listBoundMethods();
} }
final long timeEnd = System.nanoTime();
affirm( SQLite3Jni.uncacheJniEnv() ); affirm( SQLite3Jni.uncacheJniEnv() );
affirm( !SQLite3Jni.uncacheJniEnv() ); affirm( !SQLite3Jni.uncacheJniEnv() );
outln("Tests done. Metrics:"); outln("Tests done. Metrics:");
@ -1172,7 +1189,7 @@ public class Tester1 {
outln("\tSQLite3Jni sqlite3_*() methods: "+ outln("\tSQLite3Jni sqlite3_*() methods: "+
nNatives+" native methods and "+ nNatives+" native methods and "+
(nMethods - nNatives)+" Java impls"); (nMethods - nNatives)+" Java impls");
outln("\tTotal time = " outln("\tTotal test time = "
+((timeEnd - timeStart)/1000000.0)+"ms"); +((timeEnd - timeStart)/1000000.0)+"ms");
} }
} }

View File

@ -1,5 +1,5 @@
C Bring\shandling\sof\sthe\sJava\sauto-ext\shandler\smore\sin\sline\swith\sthe\score\sin\sterms\sof\slocking\sand\smutability\sduring\straversal.\sThis\sremoves\sthe\sexplicit\ssynchronous\srequirement\sfrom\sthe\sJava\sopen()\sand\sauto-ext\sbindings. C Minor\sreshaping\sof\sTester1\smoving\stowards\smaking\sa\smulti-threaded\srun\smode.
D 2023-08-14T17:12:55.531 D 2023-08-15T09:26:47.524
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -254,8 +254,8 @@ F ext/jni/src/org/sqlite/jni/ProgressHandler.java 6f62053a828a572de809828b1ee495
F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86
F ext/jni/src/org/sqlite/jni/RollbackHook.java b04c8abcc6ade44a8a57129e33765793f69df0ba909e49ba18d73f4268d92564 F ext/jni/src/org/sqlite/jni/RollbackHook.java b04c8abcc6ade44a8a57129e33765793f69df0ba909e49ba18d73f4268d92564
F ext/jni/src/org/sqlite/jni/SQLFunction.java 09ce81c1c637e31c3a830d4c859cce95d65f5e02ff45f8bd1985b3479381bc46 F ext/jni/src/org/sqlite/jni/SQLFunction.java 09ce81c1c637e31c3a830d4c859cce95d65f5e02ff45f8bd1985b3479381bc46
F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 5897c1d11f6c780825c7ac739270365e6312990195fc135fc6b02d5536dbae18 F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 99334f54f5f41feb4c14dc988b93219e37799e032f2bc07bda6323b1dfb99e75
F ext/jni/src/org/sqlite/jni/Tester1.java 368e836d943d9e882d2a217d0f582ed4141d164f174bebc50715acd57549a09b F ext/jni/src/org/sqlite/jni/Tester1.java 63f02d45ad073ac9d98eb7d681a024b38f6abf978dd1454be9346cbf347b1b57
F ext/jni/src/org/sqlite/jni/TesterFts5.java 59e22dd24af033ea8827d36225a2f3297908fb6af8818ead8850c6c6847557b1 F ext/jni/src/org/sqlite/jni/TesterFts5.java 59e22dd24af033ea8827d36225a2f3297908fb6af8818ead8850c6c6847557b1
F ext/jni/src/org/sqlite/jni/Tracer.java a5cece9f947b0af27669b8baec300b6dd7ff859c3e6a6e4a1bd8b50f9714775d F ext/jni/src/org/sqlite/jni/Tracer.java a5cece9f947b0af27669b8baec300b6dd7ff859c3e6a6e4a1bd8b50f9714775d
F ext/jni/src/org/sqlite/jni/UpdateHook.java e58645a1727f8a9bbe72dc072ec5b40d9f9362cb0aa24acfe93f49ff56a9016d F ext/jni/src/org/sqlite/jni/UpdateHook.java e58645a1727f8a9bbe72dc072ec5b40d9f9362cb0aa24acfe93f49ff56a9016d
@ -2091,8 +2091,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P c84ded0e59aea4861d72b53b4b40cf580747c0f6ca58c334a996f1a825276cb5 P 42994b952e092ae4fa319395208622e887387ca3ff8ac57961c824a6c272bf0e
R 49ea94318acd6a04e4782997e6036b52 R efccc6a7a6eed17207843d66c0fb4c2d
U stephan U stephan
Z f760a4c17dc36361fbad3526fa5aa4c4 Z 6864924ac8d4acb7bd32dec052e883fa
# Remove this line to create a well-formed Fossil manifest. # Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
42994b952e092ae4fa319395208622e887387ca3ff8ac57961c824a6c272bf0e f104c14c26c123ee78c09fc1bc59efb8668dc624da05c1d8dbeaf3c9dd02a393