From 3f8df3a3b42dbf54f99da2c82adb9f715d879f4c Mon Sep 17 00:00:00 2001 From: Bret McGuire Date: Thu, 27 May 2021 14:59:48 -0500 Subject: [PATCH 1/6] Baseline support, need to update the tests --- python/adelphi/adelphi/nb.py | 19 +++++++++++++------ python/adelphi/bin/adelphi | 8 +++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/python/adelphi/adelphi/nb.py b/python/adelphi/adelphi/nb.py index b3cde0a..deb0452 100644 --- a/python/adelphi/adelphi/nb.py +++ b/python/adelphi/adelphi/nb.py @@ -89,7 +89,12 @@ def __init__(self, cluster, props): self.rampup_cycles = props["rampup-cycles"] self.main_cycles = props["main-cycles"] - self.numeric_max = min((self.rampup_cycles + self.main_cycles) * 1000, MAX_NUMERIC_VAL) + self.scenario_name = props["scenario-name"] + self.numeric_max = \ + min((self.rampup_cycles + self.main_cycles) * 1000, MAX_NUMERIC_VAL) \ + if self.rampup_cycles and self.main_cycles \ + else MAX_NUMERIC_VAL + # Always disable anonymization when generating nosqlbench configs real_props = props.copy() @@ -107,8 +112,10 @@ def __init__(self, cluster, props): self.table = next(iter(self.keyspace.tables.values())) log.info("Creating nosqlbench config for {}.{}".format(self.keyspace.name, self.table.name)) - log.info("Number of cycles for rampup phase = {}".format(self.rampup_cycles)) - log.info("Number of cycles for main phase = {}".format(self.main_cycles)) + if self.rampup_cycles: + log.info("Number of cycles for rampup phase = {}".format(self.rampup_cycles)) + if self.main_cycles: + log.info("Number of cycles for main phase = {}".format(self.main_cycles)) log.info("Max numeric value = {}".format(self.numeric_max)) @@ -125,11 +132,11 @@ def each_keyspace(self, ks_fn): def __get_rampup_scenario(self): - return RAMPUP_SCENARIO.format(self.rampup_cycles) + return RAMPUP_SCENARIO.format(self.rampup_cycles or "TEMPLATE(rampup-cycles,1000)") def __get_main_scenario(self): - return MAIN_SCENARIO.format(self.main_cycles) + return MAIN_SCENARIO.format(self.main_cycles or "TEMPLATE(main-cycles,1000)") def __get_dist(self, typename): @@ -172,7 +179,7 @@ def __build_schema(self): """Really more of a config than a schema, but we'll allow it""" root = {} - root["scenarios"] = {"TEMPLATE(scenarioname,default)":[self.__get_rampup_scenario(), self.__get_main_scenario()]} + root["scenarios"] = {self.scenario_name or "TEMPLATE(scenarioname,default)":[self.__get_rampup_scenario(), self.__get_main_scenario()]} root["bindings"] = self.__build_bindings(self.table) diff --git a/python/adelphi/bin/adelphi b/python/adelphi/bin/adelphi index 20f3e32..b6579fd 100644 --- a/python/adelphi/bin/adelphi +++ b/python/adelphi/bin/adelphi @@ -229,15 +229,17 @@ def contribute(ctx, token): @export.command() -@click.option('--rampup-cycles', type=int, default=1000, help='Number of cycles to use for the nosqlbench rampup phase') -@click.option('--main-cycles', type=int, default=1000, help='Number of cycles to use for the nosqlbench main phase') +@click.option('--rampup-cycles', type=int, help='Number of cycles to use for the nosqlbench rampup phase') +@click.option('--main-cycles', type=int, help='Number of cycles to use for the nosqlbench main phase') +@click.option('--scenario-name', type=str, help='Name of the nosqlbench scenario') @click.pass_context -def export_nb(ctx, rampup_cycles, main_cycles): +def export_nb(ctx, rampup_cycles, main_cycles, scenario_name): """Export a schema in a format suitable for use with the the nosqlbench performance test framework""" ctx.obj["include-metadata"] = False ctx.obj["rampup-cycles"] = rampup_cycles ctx.obj["main-cycles"] = main_cycles + ctx.obj["scenario-name"] = scenario_name try: exporter = build_exporter(NbExporter, ctx.obj) From 5958aa004e78e4daf8ca92c452894886a492f61e Mon Sep 17 00:00:00 2001 From: Bret McGuire Date: Thu, 27 May 2021 16:53:41 -0500 Subject: [PATCH 2/6] Normalize handling of paths in the various integration tests --- python/adelphi/tests/integration/__init__.py | 15 +++++++++++++++ .../integration/cql/test_cql_export_outputdir.py | 4 +--- .../test_cql_export_outputdir_some_keyspaces.py | 3 +-- .../integration/cql/test_cql_export_stdout.py | 5 +---- .../cql/test_cql_export_stdout_some_keyspaces.py | 5 +---- python/adelphi/tests/integration/nb/__init__.py | 3 +-- .../integration/nb/test_nb_export_outputdir.py | 4 ++-- .../tests/integration/nb/test_nb_export_stdout.py | 4 ++-- 8 files changed, 24 insertions(+), 19 deletions(-) diff --git a/python/adelphi/tests/integration/__init__.py b/python/adelphi/tests/integration/__init__.py index 2357b7a..d8ead87 100644 --- a/python/adelphi/tests/integration/__init__.py +++ b/python/adelphi/tests/integration/__init__.py @@ -22,6 +22,20 @@ class SchemaTestMixin: + # Resource directory management logic + def cqlReferenceSchema(self, version): + return "tests/integration/resources/cql-schemas/{}.cql".format(version) + + + def nbReferenceYaml(self, version): + return "tests/integration/resources/nb-schemas/{}.yaml".format(version) + + + def nbBaseSchema(self): + return "tests/integration/resources/nb-base-schema.cql" + + + # Temp dir logic def basePath(self, name): return os.path.join(self.dirs.basePath, name) @@ -45,6 +59,7 @@ def makeTempDirs(self): self.dirs = TempDirs(base, outputDir) + # Cassandra connection logic def connectToLocalCassandra(self): session = None while not session: diff --git a/python/adelphi/tests/integration/cql/test_cql_export_outputdir.py b/python/adelphi/tests/integration/cql/test_cql_export_outputdir.py index cbdcb44..2922a57 100644 --- a/python/adelphi/tests/integration/cql/test_cql_export_outputdir.py +++ b/python/adelphi/tests/integration/cql/test_cql_export_outputdir.py @@ -33,8 +33,6 @@ def runAdelphi(self, version): def evalAdelphiOutput(self, version): - referencePath = "tests/integration/resources/cql-schemas/{}.cql".format(version) - # Basic idea here is to find all schemas written to the output dir and aggregate them into a single schema # file. We then compare this aggregated file to the reference schema. Ordering is important here but # the current keyspace names hash to something that causes individual keyspaces to be discovered in the @@ -50,4 +48,4 @@ def evalAdelphiOutput(self, version): with open(outputSchema) as outputSchemaFile: shutil.copyfileobj(outputSchemaFile, allOutputFile) allOutputFile.write("\n") - self.compareToReferenceCql(referencePath, allOutputPath) + self.compareToReferenceCql(self.cqlReferenceSchema(version), allOutputPath) \ No newline at end of file diff --git a/python/adelphi/tests/integration/cql/test_cql_export_outputdir_some_keyspaces.py b/python/adelphi/tests/integration/cql/test_cql_export_outputdir_some_keyspaces.py index e9b79da..be803c0 100644 --- a/python/adelphi/tests/integration/cql/test_cql_export_outputdir_some_keyspaces.py +++ b/python/adelphi/tests/integration/cql/test_cql_export_outputdir_some_keyspaces.py @@ -37,8 +37,7 @@ def runAdelphi(self, version): def evalAdelphiOutput(self, version): - referencePath = "tests/integration/resources/cql-schemas/{}-ks0.cql".format(version) outputDirPath = self.outputDirPath(version) outputSchemas = glob.glob("{}/*/schema".format(outputDirPath)) self.assertEqual(len(outputSchemas), 1) - self.compareToReferenceCql(referencePath, outputSchemas[0]) + self.compareToReferenceCql(self.cqlReferenceSchema("{}-ks0".format(version)), outputSchemas[0]) \ No newline at end of file diff --git a/python/adelphi/tests/integration/cql/test_cql_export_stdout.py b/python/adelphi/tests/integration/cql/test_cql_export_stdout.py index 9bf5ee5..2fa3256 100644 --- a/python/adelphi/tests/integration/cql/test_cql_export_stdout.py +++ b/python/adelphi/tests/integration/cql/test_cql_export_stdout.py @@ -30,7 +30,4 @@ def runAdelphi(self, version): def evalAdelphiOutput(self, version): - referencePath = "tests/integration/resources/cql-schemas/{}.cql".format(version) - self.compareToReferenceCql(referencePath, self.stdoutPath(version)) - - + self.compareToReferenceCql(self.cqlReferenceSchema(version), self.stdoutPath(version)) \ No newline at end of file diff --git a/python/adelphi/tests/integration/cql/test_cql_export_stdout_some_keyspaces.py b/python/adelphi/tests/integration/cql/test_cql_export_stdout_some_keyspaces.py index 2448b66..06a03a9 100644 --- a/python/adelphi/tests/integration/cql/test_cql_export_stdout_some_keyspaces.py +++ b/python/adelphi/tests/integration/cql/test_cql_export_stdout_some_keyspaces.py @@ -30,7 +30,4 @@ def runAdelphi(self, version): def evalAdelphiOutput(self, version): - referencePath = "tests/integration/resources/cql-schemas/{}-ks0.cql".format(version) - self.compareToReferenceCql(referencePath, self.stdoutPath(version)) - - + self.compareToReferenceCql(self.cqlReferenceSchema("{}-ks0".format(version)), self.stdoutPath(version)) \ No newline at end of file diff --git a/python/adelphi/tests/integration/nb/__init__.py b/python/adelphi/tests/integration/nb/__init__.py index 0fffb1a..5c98570 100644 --- a/python/adelphi/tests/integration/nb/__init__.py +++ b/python/adelphi/tests/integration/nb/__init__.py @@ -2,8 +2,7 @@ class ExportNbMixin: - def compareToReferenceYaml(self, comparePath, version=None): - referencePath = "tests/integration/resources/nb-schemas/{}.yaml".format(version) + def compareToReferenceYaml(self, referencePath, comparePath): # Loader specification here to avoid a deprecation warning... see https://msg.pyyaml.org/load referenceYaml = yaml.load(open(referencePath), Loader=yaml.FullLoader) compareYaml = yaml.load(open(comparePath), Loader=yaml.FullLoader) diff --git a/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py b/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py index 2a239ca..67f0733 100644 --- a/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py +++ b/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py @@ -26,7 +26,7 @@ def setUp(self): def getBaseSchemaPath(self): - return "tests/integration/resources/nb-base-schema.cql" + return self.nbBaseSchema() def runAdelphi(self, version=None): @@ -40,4 +40,4 @@ def evalAdelphiOutput(self, version=None): outputDirPath = self.outputDirPath(version) outputSchemas = glob.glob("{}/*/schema".format(outputDirPath)) self.assertEqual(len(outputSchemas), 1, "Export of nosqlbench config only supports a single keyspace") - self.compareToReferenceYaml(outputSchemas[0], version) + self.compareToReferenceYaml(self.nbReferenceYaml(version), outputSchemas[0]) \ No newline at end of file diff --git a/python/adelphi/tests/integration/nb/test_nb_export_stdout.py b/python/adelphi/tests/integration/nb/test_nb_export_stdout.py index 1365c0b..82decf6 100644 --- a/python/adelphi/tests/integration/nb/test_nb_export_stdout.py +++ b/python/adelphi/tests/integration/nb/test_nb_export_stdout.py @@ -24,7 +24,7 @@ def setUp(self): def getBaseSchemaPath(self): - return "tests/integration/resources/nb-base-schema.cql" + return self.nbBaseSchema() def runAdelphi(self, version=None): @@ -34,4 +34,4 @@ def runAdelphi(self, version=None): def evalAdelphiOutput(self, version=None): - self.compareToReferenceYaml(self.stdoutPath(version), version) + self.compareToReferenceYaml(self.nbReferenceYaml(version), self.stdoutPath(version)) \ No newline at end of file From 3c6fcf20d64e02b54bf0b4b319d7f1102555b2f7 Mon Sep 17 00:00:00 2001 From: Bret McGuire Date: Thu, 27 May 2021 17:11:51 -0500 Subject: [PATCH 3/6] Fix to make tests pass for the case in which params are supplied at config construction time (i.e. no template params) --- .../adelphi/tests/integration/nb/test_nb_export_outputdir.py | 3 ++- python/adelphi/tests/integration/nb/test_nb_export_stdout.py | 3 ++- .../adelphi/tests/integration/resources/nb-schemas/2.1.22.yaml | 2 +- .../adelphi/tests/integration/resources/nb-schemas/2.2.19.yaml | 2 +- .../adelphi/tests/integration/resources/nb-schemas/3.0.23.yaml | 2 +- .../adelphi/tests/integration/resources/nb-schemas/3.11.9.yaml | 2 +- .../tests/integration/resources/nb-schemas/4.0-rc1.yaml | 2 +- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py b/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py index 67f0733..36022ae 100644 --- a/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py +++ b/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py @@ -33,7 +33,8 @@ def runAdelphi(self, version=None): stderrPath = self.stderrPath(version) outputDirPath = self.outputDirPath(version) os.mkdir(outputDirPath) - subprocess.run("adelphi --output-dir={} export-nb 2>> {}".format(outputDirPath, stderrPath), shell=True) + cmdStr = "adelphi --output-dir={} export-nb --rampup-cycles=1000 --main-cycles=1000 --scenario-name=foobar 2>> {}" + subprocess.run(cmdStr.format(outputDirPath, stderrPath), shell=True) def evalAdelphiOutput(self, version=None): diff --git a/python/adelphi/tests/integration/nb/test_nb_export_stdout.py b/python/adelphi/tests/integration/nb/test_nb_export_stdout.py index 82decf6..732c6fd 100644 --- a/python/adelphi/tests/integration/nb/test_nb_export_stdout.py +++ b/python/adelphi/tests/integration/nb/test_nb_export_stdout.py @@ -30,7 +30,8 @@ def getBaseSchemaPath(self): def runAdelphi(self, version=None): stdoutPath = self.stdoutPath(version) stderrPath = self.stderrPath(version) - subprocess.run("adelphi export-nb > {} 2>> {}".format(stdoutPath, stderrPath), shell=True) + cmdStr = "adelphi export-nb --rampup-cycles=1000 --main-cycles=1000 --scenario-name=foobar > {} 2>> {}" + subprocess.run(cmdStr.format(stdoutPath, stderrPath), shell=True) def evalAdelphiOutput(self, version=None): diff --git a/python/adelphi/tests/integration/resources/nb-schemas/2.1.22.yaml b/python/adelphi/tests/integration/resources/nb-schemas/2.1.22.yaml index 3855fa1..6ec1f9a 100644 --- a/python/adelphi/tests/integration/resources/nb-schemas/2.1.22.yaml +++ b/python/adelphi/tests/integration/resources/nb-schemas/2.1.22.yaml @@ -38,6 +38,6 @@ blocks: phase: main type: write scenarios: - TEMPLATE(scenarioname,default): + foobar: - run driver=cql tags=phase:rampup cycles=1000 threads=auto - run driver=cql tags=phase:main cycles=1000 threads=auto diff --git a/python/adelphi/tests/integration/resources/nb-schemas/2.2.19.yaml b/python/adelphi/tests/integration/resources/nb-schemas/2.2.19.yaml index 3855fa1..6ec1f9a 100644 --- a/python/adelphi/tests/integration/resources/nb-schemas/2.2.19.yaml +++ b/python/adelphi/tests/integration/resources/nb-schemas/2.2.19.yaml @@ -38,6 +38,6 @@ blocks: phase: main type: write scenarios: - TEMPLATE(scenarioname,default): + foobar: - run driver=cql tags=phase:rampup cycles=1000 threads=auto - run driver=cql tags=phase:main cycles=1000 threads=auto diff --git a/python/adelphi/tests/integration/resources/nb-schemas/3.0.23.yaml b/python/adelphi/tests/integration/resources/nb-schemas/3.0.23.yaml index 3855fa1..6ec1f9a 100644 --- a/python/adelphi/tests/integration/resources/nb-schemas/3.0.23.yaml +++ b/python/adelphi/tests/integration/resources/nb-schemas/3.0.23.yaml @@ -38,6 +38,6 @@ blocks: phase: main type: write scenarios: - TEMPLATE(scenarioname,default): + foobar: - run driver=cql tags=phase:rampup cycles=1000 threads=auto - run driver=cql tags=phase:main cycles=1000 threads=auto diff --git a/python/adelphi/tests/integration/resources/nb-schemas/3.11.9.yaml b/python/adelphi/tests/integration/resources/nb-schemas/3.11.9.yaml index 3855fa1..6ec1f9a 100644 --- a/python/adelphi/tests/integration/resources/nb-schemas/3.11.9.yaml +++ b/python/adelphi/tests/integration/resources/nb-schemas/3.11.9.yaml @@ -38,6 +38,6 @@ blocks: phase: main type: write scenarios: - TEMPLATE(scenarioname,default): + foobar: - run driver=cql tags=phase:rampup cycles=1000 threads=auto - run driver=cql tags=phase:main cycles=1000 threads=auto diff --git a/python/adelphi/tests/integration/resources/nb-schemas/4.0-rc1.yaml b/python/adelphi/tests/integration/resources/nb-schemas/4.0-rc1.yaml index 3855fa1..6ec1f9a 100644 --- a/python/adelphi/tests/integration/resources/nb-schemas/4.0-rc1.yaml +++ b/python/adelphi/tests/integration/resources/nb-schemas/4.0-rc1.yaml @@ -38,6 +38,6 @@ blocks: phase: main type: write scenarios: - TEMPLATE(scenarioname,default): + foobar: - run driver=cql tags=phase:rampup cycles=1000 threads=auto - run driver=cql tags=phase:main cycles=1000 threads=auto From e36c507eef71d8aacb82ab7649ccbe0f345e8dc2 Mon Sep 17 00:00:00 2001 From: Bret McGuire Date: Tue, 1 Jun 2021 16:49:54 -0500 Subject: [PATCH 4/6] Test for generation with template vars --- python/adelphi/adelphi/nb.py | 10 +++-- .../nb/test_nb_export_outputdir.py | 1 - .../test_nb_export_outputdir_templatevars.py | 43 +++++++++++++++++++ .../nb/test_nb_export_stdout_templatevars.py | 39 +++++++++++++++++ .../nb-schemas/2.1.22-templatevars.yaml | 43 +++++++++++++++++++ .../nb-schemas/2.2.19-templatevars.yaml | 43 +++++++++++++++++++ .../nb-schemas/3.0.23-templatevars.yaml | 43 +++++++++++++++++++ .../nb-schemas/3.11.9-templatevars.yaml | 43 +++++++++++++++++++ .../nb-schemas/4.0-rc1-templatevars.yaml | 43 +++++++++++++++++++ 9 files changed, 304 insertions(+), 4 deletions(-) create mode 100644 python/adelphi/tests/integration/nb/test_nb_export_outputdir_templatevars.py create mode 100644 python/adelphi/tests/integration/nb/test_nb_export_stdout_templatevars.py create mode 100644 python/adelphi/tests/integration/resources/nb-schemas/2.1.22-templatevars.yaml create mode 100644 python/adelphi/tests/integration/resources/nb-schemas/2.2.19-templatevars.yaml create mode 100644 python/adelphi/tests/integration/resources/nb-schemas/3.0.23-templatevars.yaml create mode 100644 python/adelphi/tests/integration/resources/nb-schemas/3.11.9-templatevars.yaml create mode 100644 python/adelphi/tests/integration/resources/nb-schemas/4.0-rc1-templatevars.yaml diff --git a/python/adelphi/adelphi/nb.py b/python/adelphi/adelphi/nb.py index deb0452..858e48e 100644 --- a/python/adelphi/adelphi/nb.py +++ b/python/adelphi/adelphi/nb.py @@ -10,6 +10,10 @@ RAMPUP_SCENARIO = "run driver=cql tags=phase:rampup cycles={} threads=auto" MAIN_SCENARIO = "run driver=cql tags=phase:main cycles={} threads=auto" +TEMPLATEVAR_RAMPUP_CYCLES = "TEMPLATE(rampup-cycles,1000)" +TEMPLATEVAR_MAIN_CYCLES = "TEMPLATE(main-cycles,1000)" +TEMPLATEVAR_SCENARIO_NAME = "TEMPLATE(scenarioname,default)" + CQL_TYPES={} CQL_TYPES["text"] = "Mod({}); ToString() -> String" CQL_TYPES["ascii"] = "Mod({}); ToString() -> String" @@ -132,11 +136,11 @@ def each_keyspace(self, ks_fn): def __get_rampup_scenario(self): - return RAMPUP_SCENARIO.format(self.rampup_cycles or "TEMPLATE(rampup-cycles,1000)") + return RAMPUP_SCENARIO.format(self.rampup_cycles or TEMPLATEVAR_RAMPUP_CYCLES) def __get_main_scenario(self): - return MAIN_SCENARIO.format(self.main_cycles or "TEMPLATE(main-cycles,1000)") + return MAIN_SCENARIO.format(self.main_cycles or TEMPLATEVAR_MAIN_CYCLES) def __get_dist(self, typename): @@ -179,7 +183,7 @@ def __build_schema(self): """Really more of a config than a schema, but we'll allow it""" root = {} - root["scenarios"] = {self.scenario_name or "TEMPLATE(scenarioname,default)":[self.__get_rampup_scenario(), self.__get_main_scenario()]} + root["scenarios"] = {self.scenario_name or TEMPLATEVAR_SCENARIO_NAME:[self.__get_rampup_scenario(), self.__get_main_scenario()]} root["bindings"] = self.__build_bindings(self.table) diff --git a/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py b/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py index 36022ae..7e5aad7 100644 --- a/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py +++ b/python/adelphi/tests/integration/nb/test_nb_export_outputdir.py @@ -2,7 +2,6 @@ import logging import os import sys -import yaml try: import unittest2 as unittest diff --git a/python/adelphi/tests/integration/nb/test_nb_export_outputdir_templatevars.py b/python/adelphi/tests/integration/nb/test_nb_export_outputdir_templatevars.py new file mode 100644 index 0000000..567d69b --- /dev/null +++ b/python/adelphi/tests/integration/nb/test_nb_export_outputdir_templatevars.py @@ -0,0 +1,43 @@ +import glob +import logging +import os +import sys + +try: + import unittest2 as unittest +except ImportError: + import unittest + +if os.name == 'posix' and sys.version_info[0] < 3: + import subprocess32 as subprocess +else: + import subprocess + +from tests.integration import SchemaTestMixin +from tests.integration.nb import ExportNbMixin + +log = logging.getLogger('adelphi') + +class TestNbExportOutputDir(unittest.TestCase, SchemaTestMixin, ExportNbMixin): + + def setUp(self): + super(TestNbExportOutputDir, self).setUp() + + + def getBaseSchemaPath(self): + return self.nbBaseSchema() + + + def runAdelphi(self, version=None): + stderrPath = self.stderrPath(version) + outputDirPath = self.outputDirPath(version) + os.mkdir(outputDirPath) + cmdStr = "adelphi --output-dir={} export-nb 2>> {}" + subprocess.run(cmdStr.format(outputDirPath, stderrPath), shell=True) + + + def evalAdelphiOutput(self, version=None): + outputDirPath = self.outputDirPath(version) + outputSchemas = glob.glob("{}/*/schema".format(outputDirPath)) + self.assertEqual(len(outputSchemas), 1, "Export of nosqlbench config only supports a single keyspace") + self.compareToReferenceYaml(self.nbReferenceYaml("{}-templatevars".format(version)), outputSchemas[0]) \ No newline at end of file diff --git a/python/adelphi/tests/integration/nb/test_nb_export_stdout_templatevars.py b/python/adelphi/tests/integration/nb/test_nb_export_stdout_templatevars.py new file mode 100644 index 0000000..7c3be44 --- /dev/null +++ b/python/adelphi/tests/integration/nb/test_nb_export_stdout_templatevars.py @@ -0,0 +1,39 @@ +import logging +import os +import sys + +try: + import unittest2 as unittest +except ImportError: + import unittest + +if os.name == 'posix' and sys.version_info[0] < 3: + import subprocess32 as subprocess +else: + import subprocess + +from tests.integration import SchemaTestMixin +from tests.integration.nb import ExportNbMixin + +log = logging.getLogger('adelphi') + +class TestNbExportStdout(unittest.TestCase, SchemaTestMixin, ExportNbMixin): + + def setUp(self): + super(TestNbExportStdout, self).setUp() + + + def getBaseSchemaPath(self): + return self.nbBaseSchema() + + + def runAdelphi(self, version=None): + stdoutPath = self.stdoutPath(version) + stderrPath = self.stderrPath(version) + cmdStr = "adelphi export-nb > {} 2>> {}" + subprocess.run(cmdStr.format(stdoutPath, stderrPath), shell=True) + + + def evalAdelphiOutput(self, version=None): + self.maxDiff = None + self.compareToReferenceYaml(self.nbReferenceYaml("{}-templatevars".format(version)), self.stdoutPath(version)) \ No newline at end of file diff --git a/python/adelphi/tests/integration/resources/nb-schemas/2.1.22-templatevars.yaml b/python/adelphi/tests/integration/resources/nb-schemas/2.1.22-templatevars.yaml new file mode 100644 index 0000000..e938b10 --- /dev/null +++ b/python/adelphi/tests/integration/resources/nb-schemas/2.1.22-templatevars.yaml @@ -0,0 +1,43 @@ +bindings: + key1_dist: Hash(); Mod(1000000000); ToString() -> String + key1_seq: Mod(1000000000); ToString() -> String + key2_dist: Hash(); Mod(1000000000); ToString() -> String + key2_seq: Mod(1000000000); ToString() -> String + value_dist: Hash(); Mod(1000000000); ToString() -> String +blocks: +- name: rampup + params: + cl: LOCAL_QUORUM + statements: + - rampup-insert: insert into "testkeyspace"."testtable" ("key1","key2","value") + values ({key1_seq},{key2_seq},{value_dist}) + tags: + name: rampup-insert + tags: + phase: rampup +- name: main-read + params: &id001 + cl: LOCAL_QUORUM + ratio: 5 + statements: + - main-select: select * from "testkeyspace"."testtable" where "key1" = {key1_dist} + and "key2" = {key2_dist} + tags: + name: main-select + tags: + phase: main + type: read +- name: main-write + params: *id001 + statements: + - main-insert: insert into "testkeyspace"."testtable" ("key1","key2","value") values + ({key1_seq},{key2_seq},{value_dist}) + tags: + name: main-insert + tags: + phase: main + type: write +scenarios: + TEMPLATE(scenarioname,default): + - run driver=cql tags=phase:rampup cycles=TEMPLATE(rampup-cycles,1000) threads=auto + - run driver=cql tags=phase:main cycles=TEMPLATE(main-cycles,1000) threads=auto diff --git a/python/adelphi/tests/integration/resources/nb-schemas/2.2.19-templatevars.yaml b/python/adelphi/tests/integration/resources/nb-schemas/2.2.19-templatevars.yaml new file mode 100644 index 0000000..e938b10 --- /dev/null +++ b/python/adelphi/tests/integration/resources/nb-schemas/2.2.19-templatevars.yaml @@ -0,0 +1,43 @@ +bindings: + key1_dist: Hash(); Mod(1000000000); ToString() -> String + key1_seq: Mod(1000000000); ToString() -> String + key2_dist: Hash(); Mod(1000000000); ToString() -> String + key2_seq: Mod(1000000000); ToString() -> String + value_dist: Hash(); Mod(1000000000); ToString() -> String +blocks: +- name: rampup + params: + cl: LOCAL_QUORUM + statements: + - rampup-insert: insert into "testkeyspace"."testtable" ("key1","key2","value") + values ({key1_seq},{key2_seq},{value_dist}) + tags: + name: rampup-insert + tags: + phase: rampup +- name: main-read + params: &id001 + cl: LOCAL_QUORUM + ratio: 5 + statements: + - main-select: select * from "testkeyspace"."testtable" where "key1" = {key1_dist} + and "key2" = {key2_dist} + tags: + name: main-select + tags: + phase: main + type: read +- name: main-write + params: *id001 + statements: + - main-insert: insert into "testkeyspace"."testtable" ("key1","key2","value") values + ({key1_seq},{key2_seq},{value_dist}) + tags: + name: main-insert + tags: + phase: main + type: write +scenarios: + TEMPLATE(scenarioname,default): + - run driver=cql tags=phase:rampup cycles=TEMPLATE(rampup-cycles,1000) threads=auto + - run driver=cql tags=phase:main cycles=TEMPLATE(main-cycles,1000) threads=auto diff --git a/python/adelphi/tests/integration/resources/nb-schemas/3.0.23-templatevars.yaml b/python/adelphi/tests/integration/resources/nb-schemas/3.0.23-templatevars.yaml new file mode 100644 index 0000000..e938b10 --- /dev/null +++ b/python/adelphi/tests/integration/resources/nb-schemas/3.0.23-templatevars.yaml @@ -0,0 +1,43 @@ +bindings: + key1_dist: Hash(); Mod(1000000000); ToString() -> String + key1_seq: Mod(1000000000); ToString() -> String + key2_dist: Hash(); Mod(1000000000); ToString() -> String + key2_seq: Mod(1000000000); ToString() -> String + value_dist: Hash(); Mod(1000000000); ToString() -> String +blocks: +- name: rampup + params: + cl: LOCAL_QUORUM + statements: + - rampup-insert: insert into "testkeyspace"."testtable" ("key1","key2","value") + values ({key1_seq},{key2_seq},{value_dist}) + tags: + name: rampup-insert + tags: + phase: rampup +- name: main-read + params: &id001 + cl: LOCAL_QUORUM + ratio: 5 + statements: + - main-select: select * from "testkeyspace"."testtable" where "key1" = {key1_dist} + and "key2" = {key2_dist} + tags: + name: main-select + tags: + phase: main + type: read +- name: main-write + params: *id001 + statements: + - main-insert: insert into "testkeyspace"."testtable" ("key1","key2","value") values + ({key1_seq},{key2_seq},{value_dist}) + tags: + name: main-insert + tags: + phase: main + type: write +scenarios: + TEMPLATE(scenarioname,default): + - run driver=cql tags=phase:rampup cycles=TEMPLATE(rampup-cycles,1000) threads=auto + - run driver=cql tags=phase:main cycles=TEMPLATE(main-cycles,1000) threads=auto diff --git a/python/adelphi/tests/integration/resources/nb-schemas/3.11.9-templatevars.yaml b/python/adelphi/tests/integration/resources/nb-schemas/3.11.9-templatevars.yaml new file mode 100644 index 0000000..e938b10 --- /dev/null +++ b/python/adelphi/tests/integration/resources/nb-schemas/3.11.9-templatevars.yaml @@ -0,0 +1,43 @@ +bindings: + key1_dist: Hash(); Mod(1000000000); ToString() -> String + key1_seq: Mod(1000000000); ToString() -> String + key2_dist: Hash(); Mod(1000000000); ToString() -> String + key2_seq: Mod(1000000000); ToString() -> String + value_dist: Hash(); Mod(1000000000); ToString() -> String +blocks: +- name: rampup + params: + cl: LOCAL_QUORUM + statements: + - rampup-insert: insert into "testkeyspace"."testtable" ("key1","key2","value") + values ({key1_seq},{key2_seq},{value_dist}) + tags: + name: rampup-insert + tags: + phase: rampup +- name: main-read + params: &id001 + cl: LOCAL_QUORUM + ratio: 5 + statements: + - main-select: select * from "testkeyspace"."testtable" where "key1" = {key1_dist} + and "key2" = {key2_dist} + tags: + name: main-select + tags: + phase: main + type: read +- name: main-write + params: *id001 + statements: + - main-insert: insert into "testkeyspace"."testtable" ("key1","key2","value") values + ({key1_seq},{key2_seq},{value_dist}) + tags: + name: main-insert + tags: + phase: main + type: write +scenarios: + TEMPLATE(scenarioname,default): + - run driver=cql tags=phase:rampup cycles=TEMPLATE(rampup-cycles,1000) threads=auto + - run driver=cql tags=phase:main cycles=TEMPLATE(main-cycles,1000) threads=auto diff --git a/python/adelphi/tests/integration/resources/nb-schemas/4.0-rc1-templatevars.yaml b/python/adelphi/tests/integration/resources/nb-schemas/4.0-rc1-templatevars.yaml new file mode 100644 index 0000000..e938b10 --- /dev/null +++ b/python/adelphi/tests/integration/resources/nb-schemas/4.0-rc1-templatevars.yaml @@ -0,0 +1,43 @@ +bindings: + key1_dist: Hash(); Mod(1000000000); ToString() -> String + key1_seq: Mod(1000000000); ToString() -> String + key2_dist: Hash(); Mod(1000000000); ToString() -> String + key2_seq: Mod(1000000000); ToString() -> String + value_dist: Hash(); Mod(1000000000); ToString() -> String +blocks: +- name: rampup + params: + cl: LOCAL_QUORUM + statements: + - rampup-insert: insert into "testkeyspace"."testtable" ("key1","key2","value") + values ({key1_seq},{key2_seq},{value_dist}) + tags: + name: rampup-insert + tags: + phase: rampup +- name: main-read + params: &id001 + cl: LOCAL_QUORUM + ratio: 5 + statements: + - main-select: select * from "testkeyspace"."testtable" where "key1" = {key1_dist} + and "key2" = {key2_dist} + tags: + name: main-select + tags: + phase: main + type: read +- name: main-write + params: *id001 + statements: + - main-insert: insert into "testkeyspace"."testtable" ("key1","key2","value") values + ({key1_seq},{key2_seq},{value_dist}) + tags: + name: main-insert + tags: + phase: main + type: write +scenarios: + TEMPLATE(scenarioname,default): + - run driver=cql tags=phase:rampup cycles=TEMPLATE(rampup-cycles,1000) threads=auto + - run driver=cql tags=phase:main cycles=TEMPLATE(main-cycles,1000) threads=auto From 1499462bf26580b1816d3a47fb3d04351fd65d20 Mon Sep 17 00:00:00 2001 From: Bret McGuire Date: Wed, 2 Jun 2021 00:22:03 -0500 Subject: [PATCH 5/6] Fixing pyaml generation of invalid YAML via attempt to export Python unicode string --- python/adelphi/adelphi/nb.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/python/adelphi/adelphi/nb.py b/python/adelphi/adelphi/nb.py index 858e48e..fa87c61 100644 --- a/python/adelphi/adelphi/nb.py +++ b/python/adelphi/adelphi/nb.py @@ -1,8 +1,6 @@ import logging import yaml -from itertools import chain - from adelphi.exceptions import KeyspaceSelectionException, TableSelectionException, ExportException from adelphi.export import BaseExporter @@ -196,4 +194,4 @@ def __build_schema(self): main_write_block = {"name":"main-write", "tags":{"phase":"main", "type":"write"}, "params":cl_ratio_map, "statements": [self.__build_main_write_statement()]} root["blocks"] = [rampup_block, main_read_block, main_write_block] - return yaml.dump(root, default_flow_style=False) + return yaml.safe_dump(root, default_flow_style=False) From ca79599c6fcc468b5c78e9e62fda639d01681115 Mon Sep 17 00:00:00 2001 From: Bret McGuire Date: Wed, 2 Jun 2021 00:47:58 -0500 Subject: [PATCH 6/6] Let's name our classes correctly shall we? --- .../integration/nb/test_nb_export_outputdir_templatevars.py | 4 ++-- .../integration/nb/test_nb_export_stdout_templatevars.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/adelphi/tests/integration/nb/test_nb_export_outputdir_templatevars.py b/python/adelphi/tests/integration/nb/test_nb_export_outputdir_templatevars.py index 567d69b..2fcbddf 100644 --- a/python/adelphi/tests/integration/nb/test_nb_export_outputdir_templatevars.py +++ b/python/adelphi/tests/integration/nb/test_nb_export_outputdir_templatevars.py @@ -18,10 +18,10 @@ log = logging.getLogger('adelphi') -class TestNbExportOutputDir(unittest.TestCase, SchemaTestMixin, ExportNbMixin): +class TestNbExportOutputDirTemplateVars(unittest.TestCase, SchemaTestMixin, ExportNbMixin): def setUp(self): - super(TestNbExportOutputDir, self).setUp() + super(TestNbExportOutputDirTemplateVars, self).setUp() def getBaseSchemaPath(self): diff --git a/python/adelphi/tests/integration/nb/test_nb_export_stdout_templatevars.py b/python/adelphi/tests/integration/nb/test_nb_export_stdout_templatevars.py index 7c3be44..021cb35 100644 --- a/python/adelphi/tests/integration/nb/test_nb_export_stdout_templatevars.py +++ b/python/adelphi/tests/integration/nb/test_nb_export_stdout_templatevars.py @@ -17,10 +17,10 @@ log = logging.getLogger('adelphi') -class TestNbExportStdout(unittest.TestCase, SchemaTestMixin, ExportNbMixin): +class TestNbExportStdoutTemplateVars(unittest.TestCase, SchemaTestMixin, ExportNbMixin): def setUp(self): - super(TestNbExportStdout, self).setUp() + super(TestNbExportStdoutTemplateVars, self).setUp() def getBaseSchemaPath(self):