|
|
@ -1,5 +1,7 @@ |
|
|
|
#!/usr/bin/env python2 |
|
|
|
#!/usr/bin/env python |
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. |
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. |
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function, unicode_literals |
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
import os |
|
|
|
import glob |
|
|
|
import glob |
|
|
|
import os.path |
|
|
|
import os.path |
|
|
@ -27,7 +29,7 @@ def my_check_output(*popenargs, **kwargs): |
|
|
|
cmd = popenargs[0] |
|
|
|
cmd = popenargs[0] |
|
|
|
raise Exception("Exit code is not 0. It is %d. Command: %s" % |
|
|
|
raise Exception("Exit code is not 0. It is %d. Command: %s" % |
|
|
|
(retcode, cmd)) |
|
|
|
(retcode, cmd)) |
|
|
|
return output |
|
|
|
return output.decode('utf-8') |
|
|
|
|
|
|
|
|
|
|
|
def run_err_null(cmd): |
|
|
|
def run_err_null(cmd): |
|
|
|
return os.system(cmd + " 2>/dev/null ") |
|
|
|
return os.system(cmd + " 2>/dev/null ") |
|
|
@ -52,7 +54,6 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
""" |
|
|
|
""" |
|
|
|
All command-line params must be specified. |
|
|
|
All command-line params must be specified. |
|
|
|
Allows full flexibility in testing; for example: missing db param. |
|
|
|
Allows full flexibility in testing; for example: missing db param. |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
""" |
|
|
|
output = my_check_output("./ldb %s |grep -v \"Created bg thread\"" % |
|
|
|
output = my_check_output("./ldb %s |grep -v \"Created bg thread\"" % |
|
|
|
params, shell=True) |
|
|
|
params, shell=True) |
|
|
@ -72,7 +73,6 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
""" |
|
|
|
""" |
|
|
|
All command-line params must be specified. |
|
|
|
All command-line params must be specified. |
|
|
|
Allows full flexibility in testing; for example: missing db param. |
|
|
|
Allows full flexibility in testing; for example: missing db param. |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
""" |
|
|
|
try: |
|
|
|
try: |
|
|
|
|
|
|
|
|
|
|
@ -87,7 +87,6 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
def assertRunOK(self, params, expectedOutput, unexpected=False): |
|
|
|
def assertRunOK(self, params, expectedOutput, unexpected=False): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Uses the default test db. |
|
|
|
Uses the default test db. |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
""" |
|
|
|
self.assertRunOKFull("%s %s" % (self.dbParam(self.DB_NAME), params), |
|
|
|
self.assertRunOKFull("%s %s" % (self.dbParam(self.DB_NAME), params), |
|
|
|
expectedOutput, unexpected) |
|
|
|
expectedOutput, unexpected) |
|
|
@ -99,7 +98,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
self.assertRunFAILFull("%s %s" % (self.dbParam(self.DB_NAME), params)) |
|
|
|
self.assertRunFAILFull("%s %s" % (self.dbParam(self.DB_NAME), params)) |
|
|
|
|
|
|
|
|
|
|
|
def testSimpleStringPutGet(self): |
|
|
|
def testSimpleStringPutGet(self): |
|
|
|
print "Running testSimpleStringPutGet..." |
|
|
|
print("Running testSimpleStringPutGet...") |
|
|
|
self.assertRunFAIL("put x1 y1") |
|
|
|
self.assertRunFAIL("put x1 y1") |
|
|
|
self.assertRunOK("put --create_if_missing x1 y1", "OK") |
|
|
|
self.assertRunOK("put --create_if_missing x1 y1", "OK") |
|
|
|
self.assertRunOK("get x1", "y1") |
|
|
|
self.assertRunOK("get x1", "y1") |
|
|
@ -157,7 +156,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
% (inputSst, params)) |
|
|
|
% (inputSst, params)) |
|
|
|
|
|
|
|
|
|
|
|
def testStringBatchPut(self): |
|
|
|
def testStringBatchPut(self): |
|
|
|
print "Running testStringBatchPut..." |
|
|
|
print("Running testStringBatchPut...") |
|
|
|
self.assertRunOK("batchput x1 y1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("batchput x1 y1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("scan", "x1 : y1") |
|
|
|
self.assertRunOK("scan", "x1 : y1") |
|
|
|
self.assertRunOK("batchput x2 y2 x3 y3 \"x4 abc\" \"y4 xyz\"", "OK") |
|
|
|
self.assertRunOK("batchput x2 y2 x3 y3 \"x4 abc\" \"y4 xyz\"", "OK") |
|
|
@ -167,7 +166,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
self.assertRunFAIL("batchput k1 v1 k2") |
|
|
|
self.assertRunFAIL("batchput k1 v1 k2") |
|
|
|
|
|
|
|
|
|
|
|
def testCountDelimDump(self): |
|
|
|
def testCountDelimDump(self): |
|
|
|
print "Running testCountDelimDump..." |
|
|
|
print("Running testCountDelimDump...") |
|
|
|
self.assertRunOK("batchput x.1 x1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("batchput x.1 x1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("batchput y.abc abc y.2 2 z.13c pqr", "OK") |
|
|
|
self.assertRunOK("batchput y.abc abc y.2 2 z.13c pqr", "OK") |
|
|
|
self.assertRunOK("dump --count_delim", "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8") |
|
|
|
self.assertRunOK("dump --count_delim", "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8") |
|
|
@ -176,7 +175,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
self.assertRunOK("dump --count_delim=\",\"", "x => count:2\tsize:14\nx.1 => count:1\tsize:5\ny.2 => count:1\tsize:4\ny.abc => count:1\tsize:8\nz.13c => count:1\tsize:8") |
|
|
|
self.assertRunOK("dump --count_delim=\",\"", "x => count:2\tsize:14\nx.1 => count:1\tsize:5\ny.2 => count:1\tsize:4\ny.abc => count:1\tsize:8\nz.13c => count:1\tsize:8") |
|
|
|
|
|
|
|
|
|
|
|
def testCountDelimIDump(self): |
|
|
|
def testCountDelimIDump(self): |
|
|
|
print "Running testCountDelimIDump..." |
|
|
|
print("Running testCountDelimIDump...") |
|
|
|
self.assertRunOK("batchput x.1 x1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("batchput x.1 x1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("batchput y.abc abc y.2 2 z.13c pqr", "OK") |
|
|
|
self.assertRunOK("batchput y.abc abc y.2 2 z.13c pqr", "OK") |
|
|
|
self.assertRunOK("idump --count_delim", "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8") |
|
|
|
self.assertRunOK("idump --count_delim", "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8") |
|
|
@ -185,7 +184,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
self.assertRunOK("idump --count_delim=\",\"", "x => count:2\tsize:14\nx.1 => count:1\tsize:5\ny.2 => count:1\tsize:4\ny.abc => count:1\tsize:8\nz.13c => count:1\tsize:8") |
|
|
|
self.assertRunOK("idump --count_delim=\",\"", "x => count:2\tsize:14\nx.1 => count:1\tsize:5\ny.2 => count:1\tsize:4\ny.abc => count:1\tsize:8\nz.13c => count:1\tsize:8") |
|
|
|
|
|
|
|
|
|
|
|
def testInvalidCmdLines(self): |
|
|
|
def testInvalidCmdLines(self): |
|
|
|
print "Running testInvalidCmdLines..." |
|
|
|
print("Running testInvalidCmdLines...") |
|
|
|
# db not specified |
|
|
|
# db not specified |
|
|
|
self.assertRunFAILFull("put 0x6133 0x6233 --hex --create_if_missing") |
|
|
|
self.assertRunFAILFull("put 0x6133 0x6233 --hex --create_if_missing") |
|
|
|
# No param called he |
|
|
|
# No param called he |
|
|
@ -195,7 +194,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
# hex has invalid boolean value |
|
|
|
# hex has invalid boolean value |
|
|
|
|
|
|
|
|
|
|
|
def testHexPutGet(self): |
|
|
|
def testHexPutGet(self): |
|
|
|
print "Running testHexPutGet..." |
|
|
|
print("Running testHexPutGet...") |
|
|
|
self.assertRunOK("put a1 b1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put a1 b1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("scan", "a1 : b1") |
|
|
|
self.assertRunOK("scan", "a1 : b1") |
|
|
|
self.assertRunOK("scan --hex", "0x6131 : 0x6231") |
|
|
|
self.assertRunOK("scan --hex", "0x6131 : 0x6231") |
|
|
@ -225,7 +224,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
self.assertRunOK("checkconsistency", "OK") |
|
|
|
self.assertRunOK("checkconsistency", "OK") |
|
|
|
|
|
|
|
|
|
|
|
def testTtlPutGet(self): |
|
|
|
def testTtlPutGet(self): |
|
|
|
print "Running testTtlPutGet..." |
|
|
|
print("Running testTtlPutGet...") |
|
|
|
self.assertRunOK("put a1 b1 --ttl --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put a1 b1 --ttl --create_if_missing", "OK") |
|
|
|
self.assertRunOK("scan --hex", "0x6131 : 0x6231", True) |
|
|
|
self.assertRunOK("scan --hex", "0x6131 : 0x6231", True) |
|
|
|
self.assertRunOK("dump --ttl ", "a1 ==> b1", True) |
|
|
|
self.assertRunOK("dump --ttl ", "a1 ==> b1", True) |
|
|
@ -240,7 +239,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
self.assertRunOK("checkconsistency", "OK") |
|
|
|
self.assertRunOK("checkconsistency", "OK") |
|
|
|
|
|
|
|
|
|
|
|
def testInvalidCmdLines(self): # noqa: F811 T25377293 Grandfathered in |
|
|
|
def testInvalidCmdLines(self): # noqa: F811 T25377293 Grandfathered in |
|
|
|
print "Running testInvalidCmdLines..." |
|
|
|
print("Running testInvalidCmdLines...") |
|
|
|
# db not specified |
|
|
|
# db not specified |
|
|
|
self.assertRunFAILFull("put 0x6133 0x6233 --hex --create_if_missing") |
|
|
|
self.assertRunFAILFull("put 0x6133 0x6233 --hex --create_if_missing") |
|
|
|
# No param called he |
|
|
|
# No param called he |
|
|
@ -251,7 +250,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
self.assertRunFAIL("put 0x6133 0x6233 --hex=Boo --create_if_missing") |
|
|
|
self.assertRunFAIL("put 0x6133 0x6233 --hex=Boo --create_if_missing") |
|
|
|
|
|
|
|
|
|
|
|
def testDumpLoad(self): |
|
|
|
def testDumpLoad(self): |
|
|
|
print "Running testDumpLoad..." |
|
|
|
print("Running testDumpLoad...") |
|
|
|
self.assertRunOK("batchput --create_if_missing x1 y1 x2 y2 x3 y3 x4 y4", |
|
|
|
self.assertRunOK("batchput --create_if_missing x1 y1 x2 y2 x3 y3 x4 y4", |
|
|
|
"OK") |
|
|
|
"OK") |
|
|
|
self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4") |
|
|
|
self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4") |
|
|
@ -342,7 +341,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
"--db=%s --create_if_missing" % origDbPath, dumpFilePath)) |
|
|
|
"--db=%s --create_if_missing" % origDbPath, dumpFilePath)) |
|
|
|
|
|
|
|
|
|
|
|
def testIDumpBasics(self): |
|
|
|
def testIDumpBasics(self): |
|
|
|
print "Running testIDumpBasics..." |
|
|
|
print("Running testIDumpBasics...") |
|
|
|
self.assertRunOK("put a val --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put a val --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put b val", "OK") |
|
|
|
self.assertRunOK("put b val", "OK") |
|
|
|
self.assertRunOK( |
|
|
|
self.assertRunOK( |
|
|
@ -354,7 +353,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
"'a' seq:1, type:1 => val\nInternal keys in range: 1") |
|
|
|
"'a' seq:1, type:1 => val\nInternal keys in range: 1") |
|
|
|
|
|
|
|
|
|
|
|
def testMiscAdminTask(self): |
|
|
|
def testMiscAdminTask(self): |
|
|
|
print "Running testMiscAdminTask..." |
|
|
|
print("Running testMiscAdminTask...") |
|
|
|
# These tests need to be improved; for example with asserts about |
|
|
|
# These tests need to be improved; for example with asserts about |
|
|
|
# whether compaction or level reduction actually took place. |
|
|
|
# whether compaction or level reduction actually took place. |
|
|
|
self.assertRunOK("batchput --create_if_missing x1 y1 x2 y2 x3 y3 x4 y4", |
|
|
|
self.assertRunOK("batchput --create_if_missing x1 y1 x2 y2 x3 y3 x4 y4", |
|
|
@ -390,7 +389,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4") |
|
|
|
self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4") |
|
|
|
|
|
|
|
|
|
|
|
def testCheckConsistency(self): |
|
|
|
def testCheckConsistency(self): |
|
|
|
print "Running testCheckConsistency..." |
|
|
|
print("Running testCheckConsistency...") |
|
|
|
|
|
|
|
|
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) |
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) |
|
|
|
self.assertRunOK("put x1 y1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put x1 y1 --create_if_missing", "OK") |
|
|
@ -414,7 +413,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
params, dumpFile)) |
|
|
|
params, dumpFile)) |
|
|
|
|
|
|
|
|
|
|
|
def testDumpLiveFiles(self): |
|
|
|
def testDumpLiveFiles(self): |
|
|
|
print "Running testDumpLiveFiles..." |
|
|
|
print("Running testDumpLiveFiles...") |
|
|
|
|
|
|
|
|
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) |
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) |
|
|
|
self.assertRunOK("put x1 y1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put x1 y1 --create_if_missing", "OK") |
|
|
@ -439,7 +438,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
return 0 == run_err_null("cp " + src + " " + dest) |
|
|
|
return 0 == run_err_null("cp " + src + " " + dest) |
|
|
|
|
|
|
|
|
|
|
|
def testManifestDump(self): |
|
|
|
def testManifestDump(self): |
|
|
|
print "Running testManifestDump..." |
|
|
|
print("Running testManifestDump...") |
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) |
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) |
|
|
|
self.assertRunOK("put 1 1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put 1 1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put 2 2", "OK") |
|
|
|
self.assertRunOK("put 2 2", "OK") |
|
|
@ -475,7 +474,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
isPattern=True) |
|
|
|
isPattern=True) |
|
|
|
|
|
|
|
|
|
|
|
def testSSTDump(self): |
|
|
|
def testSSTDump(self): |
|
|
|
print "Running testSSTDump..." |
|
|
|
print("Running testSSTDump...") |
|
|
|
|
|
|
|
|
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) |
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) |
|
|
|
self.assertRunOK("put sst1 sst1_val --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put sst1 sst1_val --create_if_missing", "OK") |
|
|
@ -495,7 +494,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
isPattern=True) |
|
|
|
isPattern=True) |
|
|
|
|
|
|
|
|
|
|
|
def testWALDump(self): |
|
|
|
def testWALDump(self): |
|
|
|
print "Running testWALDump..." |
|
|
|
print("Running testWALDump...") |
|
|
|
|
|
|
|
|
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) |
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) |
|
|
|
self.assertRunOK("put wal1 wal1_val --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put wal1 wal1_val --create_if_missing", "OK") |
|
|
@ -515,7 +514,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
isPattern=True) |
|
|
|
isPattern=True) |
|
|
|
|
|
|
|
|
|
|
|
def testListColumnFamilies(self): |
|
|
|
def testListColumnFamilies(self): |
|
|
|
print "Running testListColumnFamilies..." |
|
|
|
print("Running testListColumnFamilies...") |
|
|
|
self.assertRunOK("put x1 y1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put x1 y1 --create_if_missing", "OK") |
|
|
|
cmd = "list_column_families | grep -v \"Column families\"" |
|
|
|
cmd = "list_column_families | grep -v \"Column families\"" |
|
|
|
# Test on valid dbPath. |
|
|
|
# Test on valid dbPath. |
|
|
@ -524,7 +523,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
self.assertRunFAIL(cmd) |
|
|
|
self.assertRunFAIL(cmd) |
|
|
|
|
|
|
|
|
|
|
|
def testColumnFamilies(self): |
|
|
|
def testColumnFamilies(self): |
|
|
|
print "Running testColumnFamilies..." |
|
|
|
print("Running testColumnFamilies...") |
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) # noqa: F841 T25377293 Grandfathered in |
|
|
|
dbPath = os.path.join(self.TMP_DIR, self.DB_NAME) # noqa: F841 T25377293 Grandfathered in |
|
|
|
self.assertRunOK("put cf1_1 1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put cf1_1 1 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put cf1_2 2 --create_if_missing", "OK") |
|
|
|
self.assertRunOK("put cf1_2 2 --create_if_missing", "OK") |
|
|
@ -559,7 +558,7 @@ class LDBTestCase(unittest.TestCase): |
|
|
|
self.assertRunFAIL("drop_column_family four") |
|
|
|
self.assertRunFAIL("drop_column_family four") |
|
|
|
|
|
|
|
|
|
|
|
def testIngestExternalSst(self): |
|
|
|
def testIngestExternalSst(self): |
|
|
|
print "Running testIngestExternalSst..." |
|
|
|
print("Running testIngestExternalSst...") |
|
|
|
|
|
|
|
|
|
|
|
# Dump, load, write external sst and ingest it in another db |
|
|
|
# Dump, load, write external sst and ingest it in another db |
|
|
|
dbPath = os.path.join(self.TMP_DIR, "db1") |
|
|
|
dbPath = os.path.join(self.TMP_DIR, "db1") |
|
|
|