@@ -33,6 +33,7 @@ const pu = require('@arangodb/testutils/process-utils');
33
33
const db = arangodb . db ;
34
34
const isCluster = require ( "internal" ) . isCluster ( ) ;
35
35
const { executeExternalAndWaitWithSanitizer } = require ( '@arangodb/test-helper' ) ;
36
+ const { versionHas } = require ( "@arangodb/test-helper" ) ;
36
37
const dbs = [ { "name" : "maçã" , "id" : "9999994" , "isUnicode" : true } , {
37
38
"name" : "cachorro" ,
38
39
"id" : "9999995" ,
@@ -1359,6 +1360,102 @@ function restoreIntegrationSuite() {
1359
1360
} ;
1360
1361
}
1361
1362
1363
+ function restoreIntegrationVectorSuite ( ) {
1364
+ 'use strict' ;
1365
+ const cn = 'UnitTestsVectorIndexRestore' ;
1366
+ const arangorestore = pu . ARANGORESTORE_BIN ;
1367
+
1368
+ assertTrue ( fs . isFile ( arangorestore ) , "arangorestore not found!" ) ;
1369
+
1370
+ let addConnectionArgs = function ( args ) {
1371
+ let endpoint = arango . getEndpoint ( ) . replace ( / \+ v p p / , '' ) . replace ( / ^ h t t p : / , 'tcp:' ) . replace ( / ^ h t t p s : / , 'ssl:' ) . replace ( / ^ h 2 : / , 'tcp:' ) ;
1372
+ args . push ( '--server.endpoint' ) ;
1373
+ args . push ( endpoint ) ;
1374
+ if ( args . indexOf ( "--all-databases" ) === - 1 && args . indexOf ( "--server.database" ) === - 1 ) {
1375
+ args . push ( '--server.database' ) ;
1376
+ args . push ( arango . getDatabaseName ( ) ) ;
1377
+ }
1378
+ args . push ( '--server.username' ) ;
1379
+ args . push ( arango . connectedUser ( ) ) ;
1380
+ } ;
1381
+
1382
+ let runRestore = function ( path , args , rc ) {
1383
+ args . push ( '--input-directory' ) ;
1384
+ args . push ( path ) ;
1385
+ addConnectionArgs ( args ) ;
1386
+
1387
+ const actualRc = executeExternalAndWaitWithSanitizer ( arangorestore , args , 'shell-restore-integration' ) ;
1388
+ assertTrue ( actualRc . hasOwnProperty ( "exit" ) , actualRc ) ;
1389
+ assertEqual ( rc , actualRc . exit , actualRc ) ;
1390
+ } ;
1391
+
1392
+ return {
1393
+
1394
+ setUp : function ( ) {
1395
+ db . _drop ( cn ) ;
1396
+ } ,
1397
+
1398
+ tearDown : function ( ) {
1399
+ db . _drop ( cn ) ;
1400
+ db . _databases ( ) . forEach ( ( database ) => {
1401
+ if ( database !== "_system" ) {
1402
+ db . _dropDatabase ( database ) ;
1403
+ }
1404
+ } ) ;
1405
+ } ,
1406
+
1407
+ testRestoreVectorIndex : function ( ) {
1408
+ let path = fs . getTempFile ( ) ;
1409
+ fs . makeDirectory ( path ) ;
1410
+ let fn = fs . join ( path , cn + ".structure.json" ) ;
1411
+ fs . write ( fn , JSON . stringify ( {
1412
+ indexes : [ ] ,
1413
+ parameters : {
1414
+ indexes : [
1415
+ { id : "0" , fields : [ "_key" ] , type : "primary" , unique : true } ,
1416
+ { id : "95" , fields : [ "vector" ] , type : "vector" , params : { dimension : 4 , nLists :4 , metric : "l2" } } ,
1417
+ { id : "295" , fields : [ "value" ] , type : "persistent" , sparse : true } ,
1418
+ ] ,
1419
+ name : cn ,
1420
+ numberOfShards : 3 ,
1421
+ type : 2
1422
+ }
1423
+ } ) ) ;
1424
+ let data = [ ] ;
1425
+ for ( let i = 0 ; i < 1000 ; ++ i ) {
1426
+ data . push ( { _key : "test" + i , value : i , vector : [ 0 , i / 10 , i / 100 , i / 1000 ] } ) ;
1427
+ }
1428
+ createCollectionDataFile ( data , path , cn , /*split*/ false ) ;
1429
+
1430
+ let args = [ '--collection' , cn , '--import-data' , 'true' ] ;
1431
+ runRestore ( path , args , 0 ) ;
1432
+
1433
+ let c = db . _collection ( cn ) ;
1434
+ let indexes = c . indexes ( ) ;
1435
+ assertEqual ( 3 , indexes . length ) ;
1436
+ assertEqual ( "primary" , indexes [ 0 ] . type ) ;
1437
+ assertEqual ( [ "_key" ] , indexes [ 0 ] . fields ) ;
1438
+ assertEqual ( "vector" , indexes [ 1 ] . type ) ;
1439
+ assertEqual ( [ "vector" ] , indexes [ 1 ] . fields ) ;
1440
+ assertEqual ( "persistent" , indexes [ 2 ] . type ) ;
1441
+ assertEqual ( [ "value" ] , indexes [ 2 ] . fields ) ;
1442
+
1443
+ // test if the vector index works
1444
+ for ( let i = 0 ; i < 100 ; ++ i ) {
1445
+ c . insert ( { value : i , vector : [ 0 , 0 , 0 , 0 ] } ) ;
1446
+ }
1447
+ let result = db . _query ( "FOR doc IN " + cn + " LET dist = APPROX_NEAR_L2(doc.vector, [0, 0, 0, 0]) SORT dist LIMIT 10 RETURN doc" ) . toArray ( ) ;
1448
+ assertEqual ( 10 , result . length ) ;
1449
+ fs . removeDirectoryRecursive ( path , true ) ;
1450
+ }
1451
+ } ;
1452
+ }
1453
+
1454
+
1362
1455
jsunity . run ( restoreIntegrationSuite ) ;
1363
1456
1457
+ if
4AB7
( ! versionHas ( "arm" ) ) {
1458
+ jsunity . run ( restoreIntegrationVectorSuite ) ;
1459
+ }
1460
+
1364
1461
return jsunity . done ( ) ;
0 commit comments