'test for synchronously refreshing all cluster metadata
test_refresh_schema_metadata tests all cluster metadata is refreshed when calling refresh_schema_metadata().
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 alters the cluster, creating a new keyspace, using the first cluster
object, and verifies that the cluster metadata has not changed in the second cluster object. It then calls
refresh_schema_metadata() and verifies that the cluster metadata is updated in the second cluster object.
Similarly, it then proceeds to altering keyspace, table, UDT, UDF, and UDA metadata and subsequently verfies
that these metadata is updated when refresh_schema_metadata() is called.
@since 2.6.0
@jira_ticket PYTHON-291
@expected_result Cluster, keyspace, table, UDT, UDF, and UDA metadata should be refreshed when refresh_schema_metadata() is called.
@test_category metadata'

def test_refresh_schema_metadata(self):

    cluster2 = Cluster(protocol_version=PROTOCOL_VERSION, schema_event_refresh_window=(-1))
    cluster2.connect()
    self.assertNotIn('new_keyspace', cluster2.metadata.keyspaces)
    self.session.execute("CREATE    KEYSPACE    new_keyspace    WITH    replication    =    {'class':    'SimpleStrategy',    'replication_factor':    '1'}")
    self.assertNotIn('new_keyspace', cluster2.metadata.keyspaces)
    cluster2.refresh_schema_metadata()
    self.assertIn('new_keyspace', cluster2.metadata.keyspaces)
    self.session.execute('ALTER    KEYSPACE    {0}    WITH    durable_writes    =    false'.format(self.keyspace_name))
    self.assertTrue(cluster2.metadata.keyspaces[self.keyspace_name].durable_writes)
    cluster2.refresh_schema_metadata()
    self.assertFalse(cluster2.metadata.keyspaces[self.keyspace_name].durable_writes)
    table_name = 'test'
    self.session.execute('CREATE    TABLE    {0}.{1}    (a    int    PRIMARY    KEY,    b    text)'.format(self.keyspace_name, table_name))
    cluster2.refresh_schema_metadata()
    self.session.execute('ALTER    TABLE    {0}.{1}    ADD    c    double'.format(self.keyspace_name, table_name))
    self.assertNotIn('c', cluster2.metadata.keyspaces[self.keyspace_name].tables[table_name].columns)
    cluster2.refresh_schema_metadata()
    self.assertIn('c', cluster2.metadata.keyspaces[self.keyspace_name].tables[table_name].columns)
    if (PROTOCOL_VERSION >= 3):
        self.session.execute('CREATE    TYPE    {0}.user    (age    int,    name    text)'.format(self.keyspace_name))
        self.assertEqual(cluster2.metadata.keyspaces[self.keyspace_name].user_types, {})
        cluster2.refresh_schema_metadata()
        self.assertIn('user', cluster2.metadata.keyspaces[self.keyspace_name].user_types)
    if (PROTOCOL_VERSION >= 4):
        self.session.execute("CREATE    FUNCTION    {0}.sum_int(key    int,    val    int)\n                                                                                                                                RETURNS    NULL    ON    NULL    INPUT\n                                                                                                                                RETURNS    int\n                                                                                                                                LANGUAGE    javascript    AS    'key    +    val';".format(self.keyspace_name))
        self.assertEqual(cluster2.metadata.keyspaces[self.keyspace_name].functions, {})
        cluster2.refresh_schema_metadata()
        self.assertIn('sum_int(int,int)', cluster2.metadata.keyspaces[self.keyspace_name].functions)
        self.session.execute('CREATE    AGGREGATE    {0}.sum_agg(int)\n                                                                                                                                    SFUNC    sum_int\n                                                                                                                                    STYPE    int\n                                                                                                                                    INITCOND    0'.format(self.keyspace_name))
        self.assertEqual(cluster2.metadata.keyspaces[self.keyspace_name].aggregates, {})
        cluster2.refresh_schema_metadata()
        self.assertIn('sum_agg(int)', cluster2.metadata.keyspaces[self.keyspace_name].aggregates)
    self.session.execute('DROP    KEYSPACE    new_keyspace')
    self.assertIn('new_keyspace', cluster2.metadata.keyspaces)
    cluster2.refresh_schema_metadata()
    self.assertNotIn('new_keyspace', cluster2.metadata.keyspaces)
    cluster2.shutdown()
