Example #1
0
    def test_from_dict_with_bad_dicts(self):
        store_configs = {"dir": {}}
        with self.assertRaises(jsonschema.exceptions.ValidationError) as cm:
            DataStorePool.from_dict(store_configs)
        self.assertTrue("'store_id' is a required property"
                        in f'{cm.exception}',
                        msg=f'{cm.exception}')

        store_configs = {"dir": {"store_id": 10}}
        with self.assertRaises(jsonschema.exceptions.ValidationError) as cm:
            DataStorePool.from_dict(store_configs)
        self.assertTrue("Failed validating 'type' in schema"
                        in f'{cm.exception}',
                        msg=f'{cm.exception}')
Example #2
0
 def test_multi_stores_with_params(self):
     """Just test many stores at once"""
     store_configs = {
         "ram-1": {
             "store_id": "memory",
         },
         "ram-2": {
             "store_id": "memory",
         },
         "local-1": {
             "store_id": "file",
             "store_params": {
                 "root": "/home/bibo/datacubes-1",
             }
         },
         "local-2": {
             "store_id": "file",
             "store_params": {
                 "root": "/home/bibo/datacubes-2",
             }
         },
     }
     pool = DataStorePool.from_dict(store_configs)
     self.assertIsInstance(pool, DataStorePool)
     self.assertEqual(["local-1", "local-2", "ram-1", "ram-2"], pool.store_instance_ids)
     for instance_id in pool.store_instance_ids:
         self.assertTrue(pool.has_store_instance(instance_id))
         self.assertIsInstance(pool.get_store_config(instance_id), DataStoreConfig)
         self.assertIsInstance(pool.get_store(instance_id), DataStore)
Example #3
0
 def test_close_all_stores(self):
     store_configs = {
         "ram-1": {
             "store_id": "memory",
         },
     }
     pool = DataStorePool.from_dict(store_configs)
     # Smoke test, we do not expect any visible state changes after close_all_stores()
     pool.close_all_stores()
Example #4
0
 def test_from_dict_no_store_params(self):
     store_configs = {
         "ram-1": {
             "store_id": "memory"
         }
     }
     pool = DataStorePool.from_dict(store_configs)
     self.assertIsInstance(pool, DataStorePool)
     self.assertEqual(["ram-1"], pool.store_instance_ids)
     self.assertIsInstance(pool.get_store_config('ram-1'), DataStoreConfig)
Example #5
0
 def test_get_store(self):
     store_configs = {
         "dir-1": {
             "store_id": "directory",
             "store_params": {
                 "base_dir": "bibo"
             }
         },
     }
     pool = DataStorePool.from_dict(store_configs)
     store = pool.get_store('dir-1')
     self.assertIsInstance(store, DirectoryDataStore)
     self.assertEqual('bibo', store.base_dir)
     # Should stay same instance
     self.assertIs(store, pool.get_store('dir-1'))
     self.assertIs(store, pool.get_store('dir-1'))
Example #6
0
 def test_get_store(self):
     store_configs = {
         "dir-1": {
             "store_id": "file",
             "store_params": {
                 "root": "./bibo"
             }
         },
     }
     pool = DataStorePool.from_dict(store_configs)
     store = pool.get_store('dir-1')
     self.assertTrue(hasattr(store, 'root'))
     # noinspection PyUnresolvedReferences
     self.assertTrue(os.path.isabs(store.root))
     self.assertFalse(os.path.exists(store.root))
     # Should stay same instance
     self.assertIs(store, pool.get_store('dir-1'))
     self.assertIs(store, pool.get_store('dir-1'))
Example #7
0
 def test_from_dict_empty(self):
     pool = DataStorePool.from_dict({})
     self.assertIsInstance(pool, DataStorePool)
     self.assertEqual([], pool.store_instance_ids)
     self.assertEqual([], pool.store_configs)