forked from aerospike/aerospike-client-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_get.js
More file actions
72 lines (63 loc) · 2.66 KB
/
batch_get.js
File metadata and controls
72 lines (63 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// *****************************************************************************
// Copyright 2013-2019 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
'use strict'
/* global expect, describe, it */
const Aerospike = require('../lib/aerospike')
const helper = require('./test_helper')
const keygen = helper.keygen
const metagen = helper.metagen
const recgen = helper.recgen
const putgen = helper.putgen
const valgen = helper.valgen
describe('client.batchGet()', function () {
var client = helper.client
it('should successfully read 10 records', function () {
var numberOfRecords = 10
var kgen = keygen.string(helper.namespace, helper.set, { prefix: 'test/batch_get/success', random: false })
var mgen = metagen.constant({ ttl: 1000 })
var rgen = recgen.record({ i: valgen.integer(), s: valgen.string(), b: valgen.bytes() })
return putgen.put(numberOfRecords, kgen, rgen, mgen)
.then(records => {
const keys = records.map(record => record.key)
return client.batchGet(keys)
.then(results => {
expect(results.length).to.equal(numberOfRecords)
results.forEach(result => {
const putRecord = records.find(record => record.key.key === result.record.key.key)
expect(result.status).to.equal(Aerospike.status.OK)
expect(result.record.bins).to.eql(putRecord.bins)
})
})
})
})
it('should fail reading 10 records', function (done) {
var numberOfRecords = 10
var kgen = keygen.string(helper.namespace, helper.set, { prefix: 'test/batch_get/fail/', random: false })
var keys = keygen.range(kgen, numberOfRecords)
client.batchGet(keys, function (err, results) {
expect(err).not.to.be.ok()
expect(results.length).to.equal(numberOfRecords)
results.forEach(function (result) {
expect(result.status).to.equal(Aerospike.status.ERR_RECORD_NOT_FOUND)
})
done()
})
})
it('returns an empty array when no keys are passed', () => {
client.batchGet([])
.then(results => expect(results).to.eql([]))
})
})