11/*jshint globalstrict:false, strict:false, unused: false */
2- /*global assertEqual, assertTrue, arango, ARGUMENTS */
2+ /*global assertEqual, assertTrue, arango, ARGUMENTS, SYS_IS_V8_BUILD, print */
33
44// //////////////////////////////////////////////////////////////////////////////
55// / DISCLAIMER
@@ -274,6 +274,92 @@ function ReplicationSuite() {
274274 return trx ;
275275 } ;
276276
277+ ////////////////////////////////////////////////////////////////////////////////
278+ // client transactions
279+ let generateInsertNew = function ( collections ) {
280+ let c = collections [ Math . floor ( Math . random ( ) * collections . length ) ] ;
281+ let key = nextKey ( ) ;
282+ keys [ c ] [ key ] = 1 ;
283+
284+ return "tx.collection(" + JSON . stringify ( c ) + ").insert({ _key: " + JSON . stringify ( key ) + ", value: \"thisIsSomeStringValue\" });" ;
285+ } ;
286+
287+ let generateUpdateNew = function ( collections ) {
288+ let c = collections [ Math . floor ( Math . random ( ) * collections . length ) ] ;
289+ let all = Object . keys ( keys [ c ] ) ;
290+ if ( all . length === 0 ) {
291+ // still empty, turn into an insert first
292+ return generateInsertNew ( collections ) ;
293+ }
294+ let key = all [ Math . floor ( Math . random ( ) * all . length ) ] ;
295+ return "tx.collection(" + JSON . stringify ( c ) + ").update(" + JSON . stringify ( key ) + ", { value: \"thisIsSomeUpdatedStringValue\" });" ;
296+ } ;
297+
298+ let generateReplaceNew = function ( collections ) {
299+ let c = collections [ Math . floor ( Math . random ( ) * collections . length ) ] ;
300+ let all = Object . keys ( keys [ c ] ) ;
301+ if ( all . length === 0 ) {
302+ // still empty, turn into an insert first
303+ return generateInsertNew ( collections ) ;
304+ }
305+ let key = all [ Math . floor ( Math . random ( ) * all . length ) ] ;
306+ return "tx.collection(" + JSON . stringify ( c ) + ").replace(" + JSON . stringify ( key ) + ", { value: \"thisIsSomeReplacedStringValue\" });" ;
307+ } ;
308+
309+ let generateRemoveNew = function ( collections ) {
310+ let c = collections [ Math . floor ( Math . random ( ) * collections . length ) ] ;
311+ let all = Object . keys ( keys [ c ] ) ;
312+ if ( all . length === 0 ) {
313+ // still empty, turn into an insert first
314+ return generateInsertNew ( collections ) ;
315+ }
316+ let key = all [ Math . floor ( Math . random ( ) * all . length ) ] ;
317+ delete keys [ c ] [ key ] ;
318+ return "tx.collection(" + JSON . stringify ( c ) + ").remove(" + JSON . stringify ( key ) + ");" ;
319+ } ;
320+
321+ let generateTruncateNew = function ( collections ) {
322+ let c = collections [ Math . floor ( Math . random ( ) * collections . length ) ] ;
323+ keys [ c ] = { } ;
324+ return "tx.collection(" + JSON . stringify ( c ) + ").truncate();" ;
325+ } ;
326+
327+ let allNewOps = [
328+ { name : "insert" , generate : generateInsertNew } ,
329+ { name : "update" , generate : generateUpdateNew } ,
330+ { name : "replace" , generate : generateReplaceNew } ,
331+ { name : "remove" , generate : generateRemoveNew } ,
332+ // { name: "truncate", generate: generateTruncateNew }
333+ ] ;
334+ let executeTransaction = function ( state ) {
335+ let trx = { collections : { read : [ ] , write : [ ] } } ;
336+
337+ // determine collections
338+ do {
339+ if ( Math . random ( ) >= 0.5 ) {
340+ trx . collections . write . push ( cn ) ;
341+ }
342+ if ( Math . random ( ) >= 0.5 ) {
343+ trx . collections . write . push ( cn2 ) ;
344+ }
345+ if ( Math . random ( ) >= 0.5 ) {
346+ trx . collections . write . push ( cn3 ) ;
347+ }
348+ } while ( trx . collections . write . length === 0 ) ;
349+
350+ const tx = db . _createTransaction ( trx ) ;
351+ let txFn ;
352+ let n = Math . floor ( Math . random ( ) * 100 ) + 1 ;
353+ let ops = "txFn = function(tx) {\n let db = require('internal').db;\n " ;
354+ for ( let i = 0 ; i < n ; ++ i ) {
355+ ops += allNewOps [ Math . floor ( Math . random ( ) * allNewOps . length ) ] . generate ( trx . collections . write ) + "\n " ;
356+ }
357+ ops += "\n}" ;
358+ eval ( ops ) ;
359+ txFn ( tx ) ;
360+ return tx . commit ( ) ;
361+ } ;
362+
277363 db . _useDatabase ( cn ) ;
278364 connectToLeader ( ) ;
279365
@@ -283,8 +369,13 @@ function ReplicationSuite() {
283369
284370 function ( state ) {
285371 for ( let i = 0 ; i < 10000 ; ++ i ) {
286- let trx = createTransaction ( state ) ;
287- db . _executeTransaction ( trx ) ;
372+ if ( SYS_IS_V8_BUILD ) {
373+ let trx = createTransaction ( state ) ;
374+ db . _executeTransaction ( trx ) ;
375+ } else {
376+ print ( '.' ) ;
377+ executeTransaction ( ) ;
378+ }
288379 }
289380
290381 state . checksum = collectionChecksum ( cn ) ;
0 commit comments