summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/test/qa-tests/jstests/restore/oplog_replay_and_limit.js
blob: 378e018f155655c833ae735e14170b4b2d119ee3 (plain)
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
73
74
75
76
77
78
(function() {

  if (typeof getToolTest === 'undefined') {
    load('jstests/configs/plain_28.config.js');
  }

  if (dump_targets !== "standard") {
    print('skipping test incompatable with archiving or compression');
    return assert(true);
  }

  // Tests using mongorestore with the --oplogReplay and --oplogLimit flags.

  jsTest.log('Testing restoration with the --oplogReplay and --oplogLimit options');

  var toolTest = getToolTest('oplog_replay_and_limit');
  var commonToolArgs = getCommonToolArguments();

  // this test uses the testdata/dump_with_oplog directory. this directory contains:
  // - a test/ subdirectory, which will restore objects { _id: i } for i from
  //      0-9 to the test.data collection
  // - an oplog.bson file, which contains oplog entries for inserts of
  //      objects { _id: i } for i from 10-14 to the test.data collection.
  //
  // within the oplog.bson file, the entries for i from 10-13 have timestamps
  //      1416342265:2 through 1416342265:5. the entry for { _id: i } has
  //      timestamp 1500000000:1.

  // the db and collection we'll be using
  var testDB = toolTest.db.getSiblingDB('test');
  var testColl = testDB.data;

  // restore the data, without --oplogReplay. _ids 0-9, which appear in the
  // collection's bson file, should be restored.
  var ret = toolTest.runTool.apply(toolTest, ['restore']
    .concat(getRestoreTarget('jstests/restore/testdata/dump_with_oplog'))
    .concat(commonToolArgs));
  assert.eq(0, ret);
  assert.eq(10, testColl.count());
  for (var i = 0; i < 10; i++) {
    assert.eq(1, testColl.count({_id: i}));
  }

  // drop the db
  testDB.dropDatabase();

  // restore the data, with --oplogReplay. _ids 10-14, appearing
  // in the oplog.bson file, should be inserted as well.
  ret = toolTest.runTool.apply(toolTest, ['restore',
      '--oplogReplay']
    .concat(getRestoreTarget('jstests/restore/testdata/dump_with_oplog'))
    .concat(commonToolArgs));
  assert.eq(0, ret);
  assert.eq(15, testColl.count());
  for (i = 0; i < 15; i++) {
    assert.eq(1, testColl.count({_id: i}));
  }

  // drop the db
  testDB.dropDatabase();

  // restore the data, with --oplogReplay and --oplogLimit with a
  // value that will filter out { _id: 14 } from getting inserted.
  ret = toolTest.runTool.apply(toolTest, ['restore',
      '--oplogReplay',
      '--oplogLimit', '1416342266:0']
    .concat(getRestoreTarget('jstests/restore/testdata/dump_with_oplog'))
    .concat(commonToolArgs));
  assert.eq(0, ret);
  assert.eq(14, testColl.count());
  for (i = 0; i < 14; i++) {
    assert.eq(1, testColl.count({_id: i}));
  }

  // success
  toolTest.stop();

}());