'test for synchronously refreshing materialized view metadata
test_refresh_table_metadata_for_materialized_views tests that materialized view metadata is refreshed when calling
test_refresh_table_metatadata() with the materialized view name as the table. It creates a second cluster object
with schema_event_refresh_window=-1 such that schema refreshes are disabled for schema change push events.
It then creates a new materialized view , using the first cluster object, and verifies that the materialized view
metadata has not changed in the second cluster object. Finally, it calls test_refresh_table_metatadata() with the
materialized view name as the table name, and verifies that the materialized view metadata is updated in the
second cluster object.
@since 3.0.0
@jira_ticket PYTHON-371
@expected_result Materialized view metadata should be refreshed when refresh_table_metadata() is called.
@test_category metadata'

def test_refresh_metadata_for_mv(self):

    if (CASS_SERVER_VERSION < (3, 0)):
        raise unittest.SkipTest('Materialized    views    require    Cassandra    3.0+')
    self.session.execute('CREATE    TABLE    {0}.{1}    (a    int    PRIMARY    KEY,    b    text)'.format(self.keyspace_name, self.function_table_name))
    cluster2 = Cluster(protocol_version=PROTOCOL_VERSION, schema_event_refresh_window=(-1))
    cluster2.connect()
    try:
        self.assertNotIn('mv1', cluster2.metadata.keyspaces[self.keyspace_name].tables[self.function_table_name].views)
        self.session.execute('CREATE    MATERIALIZED    VIEW    {0}.mv1    AS    SELECT    b    FROM    {0}.{1}    WHERE    b    IS    NOT    NULL    PRIMARY    KEY    (a,    b)'.format(self.keyspace_name, self.function_table_name))
        self.assertNotIn('mv1', cluster2.metadata.keyspaces[self.keyspace_name].tables[self.function_table_name].views)
        cluster2.refresh_table_metadata(self.keyspace_name, 'mv1')
        self.assertIn('mv1', cluster2.metadata.keyspaces[self.keyspace_name].tables[self.function_table_name].views)
    finally:
        cluster2.shutdown()
    original_meta = self.cluster.metadata.keyspaces[self.keyspace_name].views['mv1']
    self.assertIs(original_meta, self.session.cluster.metadata.keyspaces[self.keyspace_name].tables[self.function_table_name].views['mv1'])
    self.cluster.refresh_materialized_view_metadata(self.keyspace_name, 'mv1')
    current_meta = self.cluster.metadata.keyspaces[self.keyspace_name].views['mv1']
    self.assertIsNot(current_meta, original_meta)
    self.assertIsNot(original_meta, self.session.cluster.metadata.keyspaces[self.keyspace_name].tables[self.function_table_name].views['mv1'])
    self.assertEqual(original_meta.as_cql_query(), current_meta.as_cql_query())
    cluster3 = Cluster(protocol_version=PROTOCOL_VERSION, schema_event_refresh_window=(-1))
    cluster3.connect()
    try:
        self.assertNotIn('mv2', cluster3.metadata.keyspaces[self.keyspace_name].tables[self.function_table_name].views)
        self.session.execute('CREATE    MATERIALIZED    VIEW    {0}.mv2    AS    SELECT    b    FROM    {0}.{1}    WHERE    b    IS    NOT    NULL    PRIMARY    KEY    (a,    b)'.format(self.keyspace_name, self.function_table_name))
        self.assertNotIn('mv2', cluster3.metadata.keyspaces[self.keyspace_name].tables[self.function_table_name].views)
        cluster3.refresh_materialized_view_metadata(self.keyspace_name, 'mv2')
        self.assertIn('mv2', cluster3.metadata.keyspaces[self.keyspace_name].tables[self.function_table_name].views)
    finally:
        cluster3.shutdown()
