def assert_data_persistence(self, version_def, nodes, digest): env = prepare_env(version_def.java_home) version = version_def.version cluster = self._new_cluster(version, nodes, self.CLUSTER_SETTINGS, env) cluster.start() with connect(cluster.node().http_url, error_trace=True) as conn: cursor = conn.cursor() wait_for_active_shards(cursor, 0) self._upgrade(cursor, version_def.upgrade_segments) cursor.execute( 'ALTER TABLE doc.t1 SET ("refresh_interval" = 4000)') run_selects(cursor, version_def.version) container = conn.get_blob_container('b1') container.get(digest) cursor.execute( 'ALTER TABLE doc.t1 SET ("refresh_interval" = 2000)') # older versions had a bug that caused this to fail if version in ('latest-nightly', '3.2'): # Test that partition and dynamic columns can be created obj = {"t_" + version.replace('.', '_'): True} args = (str(uuid4()), version, obj) cursor.execute( 'INSERT INTO doc.parted (id, version, cols) values (?, ?, ?)', args) self._process_on_stop()
def assert_meta_data(self, version_def, nodes): cluster = self._new_cluster(version_def.version, nodes, self.CLUSTER_SETTINGS, prepare_env(version_def.java_home)) cluster.start() with connect(cluster.node().http_url, error_trace=True) as conn: cursor = conn.cursor() cursor.execute(''' SELECT name, superuser FROM sys.users ORDER BY superuser, name; ''') rs = cursor.fetchall() self.assertEqual(['user_a', False], rs[0]) self.assertEqual(['crate', True], rs[1]) cursor.execute(''' SELECT fact(100); ''') self.assertEqual(9900, cursor.fetchone()[0]) cursor.execute(''' SELECT class, grantee, ident, state, type FROM sys.privileges ORDER BY class, grantee, ident, state, type ''') self.assertEqual([['SCHEMA', 'user_a', 'doc', 'GRANT', 'DDL'], ['SCHEMA', 'user_a', 'doc', 'GRANT', 'DML'], ['SCHEMA', 'user_a', 'doc', 'GRANT', 'DQL']], cursor.fetchall()) self._process_on_stop()
def _test_upgrade_path(self, versions: Tuple[VersionDef], nodes): """ Test upgrade path across specified versions. Creates a blob and regular table in first version and inserts a record, then goes through all subsequent versions - each time verifying that a few simple selects work. """ version_def = versions[0] env = prepare_env(version_def.java_home) cluster = self._new_cluster(version_def.version, nodes, self.CLUSTER_SETTINGS, env) cluster.start() digest = None with connect(cluster.node().http_url, error_trace=True) as conn: c = conn.cursor() c.execute(CREATE_ANALYZER) c.execute(CREATE_DOC_TABLE) c.execute(CREATE_PARTED_TABLE) c.execute(''' INSERT INTO t1 (id, text) VALUES (0, 'Phase queue is foo!') ''') insert_data(conn, 'doc', 't1', 10) c.execute(CREATE_BLOB_TABLE) run_selects(c, versions[0].version) container = conn.get_blob_container('b1') digest = container.put(BytesIO(b'sample data')) container.get(digest) self._process_on_stop() for version_def in versions[1:]: self.assert_data_persistence(version_def, nodes, digest) # restart with latest version version_def = versions[-1] self.assert_data_persistence(version_def, nodes, digest)
def start_cluster_and_alter_tables(self, version_def, nodes): cluster = self._new_cluster(version_def.version, nodes, self.CLUSTER_SETTINGS, prepare_env(version_def.java_home)) cluster.start() with connect(cluster.node().http_url, error_trace=True) as conn: cursor = conn.cursor() wait_for_active_shards(cursor, 8) cursor.execute(''' ALTER TABLE t1 SET (number_of_replicas=1) ''') cursor.execute(''' ALTER TABLE p1 SET (number_of_replicas=1) ''') self._process_on_stop()
def assert_dynamic_string_detection(self, version_def, nodes): """ Test that a dynamic string column detection works as expected. If the cluster was initially created/started with a lower CrateDB version, we must ensure that our default template is also upgraded, if needed, because it is persisted in the cluster state. That's why re-creating tables would not help. """ self._move_nodes_folder_if_needed() cluster = self._new_cluster(version_def.version, nodes, self.CLUSTER_SETTINGS, prepare_env(version_def.java_home)) cluster.start() with connect(cluster.node().http_url, error_trace=True) as conn: cursor = conn.cursor() cursor.execute('CREATE TABLE t1 (o object)') cursor.execute('''INSERT INTO t1 (o) VALUES ({"name" = 'foo'})''') self.assertEqual(cursor.rowcount, 1) cursor.execute('REFRESH TABLE t1') cursor.execute("SELECT o['name'], count(*) FROM t1 GROUP BY 1") rs = cursor.fetchall() self.assertEqual(['foo', 1], rs[0]) cursor.execute('DROP TABLE t1') self._process_on_stop()