@@ -2,6 +2,7 @@ const { assert } = require("chai");
22const tmp = require ( "tmp" ) ;
33const process = require ( "process" ) ;
44const path = require ( "path" ) ;
5+ const fs = require ( 'fs' ) ;
56
67const spwan = require ( "child_process" ) . spawn ;
78
@@ -131,6 +132,84 @@ describe("Database constructor", function () {
131132 testDb . close ( ) ;
132133 } ) ;
133134
135+ it ( "should create a database with throwOnWalReplayFailure configured" , async function ( ) {
136+ const tmpDbPath = await new Promise ( ( resolve , reject ) => {
137+ tmp . dir ( { unsafeCleanup : true } , ( err , path , _ ) => {
138+ if ( err ) {
139+ return reject ( err ) ;
140+ }
141+ return resolve ( path ) ;
142+ } ) ;
143+ } ) ;
144+ const dbPath = path . join ( tmpDbPath , "db.kz" ) ;
145+ const walPath = dbPath + ".wal" ;
146+ fs . writeFileSync ( walPath , "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ) ;
147+ const testDb = new kuzu . Database ( dbPath ,
148+ 1 << 28 /* 256MB */ ,
149+ true /* compression */ ,
150+ false /* readOnly */ ,
151+ 1 << 30 /* 1GB */ ,
152+ true /* autoCheckpoint */ ,
153+ 1234 /* checkpointThreshold */ ,
154+ false /* throwOnWalReplayFailure */
155+ ) ;
156+ const conn = new kuzu . Connection ( testDb ) ;
157+ let res = await conn . query ( "RETURN 1" ) ;
158+ assert . equal ( res . getNumTuples ( ) , 1 ) ;
159+ const tuple = await res . getNext ( ) ;
160+ assert . equal ( tuple [ "1" ] , 1 ) ;
161+ res . close ( ) ;
162+ conn . close ( ) ;
163+ testDb . close ( ) ;
164+ } ) ;
165+
166+ it ( "should create a database with enableChecksums configured" , async function ( ) {
167+ const tmpDbPath = await new Promise ( ( resolve , reject ) => {
168+ tmp . dir ( { unsafeCleanup : true } , ( err , path , _ ) => {
169+ if ( err ) {
170+ return reject ( err ) ;
171+ }
172+ return resolve ( path ) ;
173+ } ) ;
174+ } ) ;
175+ const dbPath = path . join ( tmpDbPath , "db.kz" ) ;
176+ let testDb = new kuzu . Database ( dbPath ,
177+ 1 << 28 /* 256MB */ ,
178+ true /* compression */ ,
179+ false /* readOnly */ ,
180+ 1 << 30 /* 1GB */ ,
181+ false /* autoCheckpoint */ ,
182+ 1234 /* checkpointThreshold */ ,
183+ true /* throwOnWalReplayFailure */ ,
184+ true /* enableChecksums */
185+ ) ;
186+ let conn = new kuzu . Connection ( testDb ) ;
187+ let res = await conn . query ( "call force_checkpoint_on_close=false" ) ;
188+ let res1 = await conn . query ( "create node table testtest1(id int64 primary key)" ) ;
189+ res . close ( ) ;
190+ res1 . close ( ) ;
191+ conn . close ( ) ;
192+ testDb . close ( ) ;
193+
194+ try {
195+ testDb = new kuzu . Database ( dbPath ,
196+ 1 << 28 /* 256MB */ ,
197+ true /* compression */ ,
198+ false /* readOnly */ ,
199+ 1 << 30 /* 1GB */ ,
200+ true /* autoCheckpoint */ ,
201+ 1234 /* checkpointThreshold */ ,
202+ true /* throwOnWalReplayFailure */ ,
203+ false /* enableChecksums */
204+ ) ;
205+ await testDb . init ( ) ;
206+ assert . fail ( "No error thrown when enableChecksums config is invalid." ) ;
207+ } catch ( e ) {
208+ assert . ok ( e . message . includes ( "Please open your database using the correct enableChecksums config." ) ) ;
209+ }
210+ testDb . close ( ) ;
211+ } ) ;
212+
134213 it ( "should create a database in read-only mode" , async function ( ) {
135214 const tmpDbPath = await new Promise ( ( resolve , reject ) => {
136215 tmp . dir ( { unsafeCleanup : true } , ( err , path , _ ) => {
0 commit comments