@Test public void provideCatalogMetadataTest() throws ConnectorException { ClusterName clusterName = new ClusterName(CLUSTER_NAME); MongoMetadataEngine spyMetadataEngine = PowerMockito.spy(MongoMetadataEngine.getInstance(connectionHandler)); TableMetadata tableMetadata1 = mock(TableMetadata.class); TableMetadata tableMetadata2 = mock(TableMetadata.class); TableName tableName1 = new TableName(DB_NAME, TABLE_NAME); TableName tableName2 = new TableName(DB_NAME, TABLE_NAME_SEC); when(tableMetadata1.getName()).thenReturn(tableName1); when(tableMetadata2.getName()).thenReturn(tableName2); Set<String> set = new TreeSet<>(); set.add(TABLE_NAME); set.add(TABLE_NAME_SEC); when(client.getDB(DB_NAME)).thenReturn(database); when(database.getCollectionNames()).thenReturn(set); PowerMockito.doReturn(tableMetadata1).when(spyMetadataEngine) .provideTableMetadata(new TableName(DB_NAME, TABLE_NAME), clusterName, connection); PowerMockito.doReturn(tableMetadata2).when(spyMetadataEngine) .provideTableMetadata(new TableName(DB_NAME, TABLE_NAME_SEC), clusterName, connection); CatalogMetadata providedCatalogMetadata = spyMetadataEngine.provideCatalogMetadata(new CatalogName(DB_NAME), clusterName, connection); Assert.assertEquals(providedCatalogMetadata.getName().getName(), DB_NAME); Assert.assertEquals(providedCatalogMetadata.getTables().size(), 2); Assert.assertEquals(providedCatalogMetadata.getTables().get(tableName1), tableMetadata1); Assert.assertEquals(providedCatalogMetadata.getTables().get(tableName2), tableMetadata2); }
@Override protected CatalogMetadata provideCatalogMetadata(CatalogName catalogName, ClusterName clusterName, Connection<MongoClient> connection) throws ConnectorException { DB db = connection.getNativeConnection().getDB(catalogName.getName()); Set<String> collectionNames = db.getCollectionNames(); CatalogMetadataBuilder catalogMetadataBuilder = new CatalogMetadataBuilder(catalogName.getName()); for (String collectionName : collectionNames) { TableName tableName = new TableName(catalogName.getName(), collectionName); catalogMetadataBuilder.withTables(provideTableMetadata(tableName, clusterName, connection)); } return catalogMetadataBuilder.build(); }
MongoMetadataEngine extends CommonsMetadataEngine<MongoClient> { @Override protected CatalogMetadata provideCatalogMetadata(CatalogName catalogName, ClusterName clusterName, Connection<MongoClient> connection) throws ConnectorException { DB db = connection.getNativeConnection().getDB(catalogName.getName()); Set<String> collectionNames = db.getCollectionNames(); CatalogMetadataBuilder catalogMetadataBuilder = new CatalogMetadataBuilder(catalogName.getName()); for (String collectionName : collectionNames) { TableName tableName = new TableName(catalogName.getName(), collectionName); catalogMetadataBuilder.withTables(provideTableMetadata(tableName, clusterName, connection)); } return catalogMetadataBuilder.build(); } }
MongoMetadataEngine extends CommonsMetadataEngine<MongoClient> { @Override protected CatalogMetadata provideCatalogMetadata(CatalogName catalogName, ClusterName clusterName, Connection<MongoClient> connection) throws ConnectorException { DB db = connection.getNativeConnection().getDB(catalogName.getName()); Set<String> collectionNames = db.getCollectionNames(); CatalogMetadataBuilder catalogMetadataBuilder = new CatalogMetadataBuilder(catalogName.getName()); for (String collectionName : collectionNames) { TableName tableName = new TableName(catalogName.getName(), collectionName); catalogMetadataBuilder.withTables(provideTableMetadata(tableName, clusterName, connection)); } return catalogMetadataBuilder.build(); } private  MongoMetadataEngine(MongoConnectionHandler connectionHandler); }
MongoMetadataEngine extends CommonsMetadataEngine<MongoClient> { @Override protected CatalogMetadata provideCatalogMetadata(CatalogName catalogName, ClusterName clusterName, Connection<MongoClient> connection) throws ConnectorException { DB db = connection.getNativeConnection().getDB(catalogName.getName()); Set<String> collectionNames = db.getCollectionNames(); CatalogMetadataBuilder catalogMetadataBuilder = new CatalogMetadataBuilder(catalogName.getName()); for (String collectionName : collectionNames) { TableName tableName = new TableName(catalogName.getName(), collectionName); catalogMetadataBuilder.withTables(provideTableMetadata(tableName, clusterName, connection)); } return catalogMetadataBuilder.build(); } private  MongoMetadataEngine(MongoConnectionHandler connectionHandler); static MongoMetadataEngine getInstance(MongoConnectionHandler connectionHandler); }
MongoMetadataEngine extends CommonsMetadataEngine<MongoClient> { @Override protected CatalogMetadata provideCatalogMetadata(CatalogName catalogName, ClusterName clusterName, Connection<MongoClient> connection) throws ConnectorException { DB db = connection.getNativeConnection().getDB(catalogName.getName()); Set<String> collectionNames = db.getCollectionNames(); CatalogMetadataBuilder catalogMetadataBuilder = new CatalogMetadataBuilder(catalogName.getName()); for (String collectionName : collectionNames) { TableName tableName = new TableName(catalogName.getName(), collectionName); catalogMetadataBuilder.withTables(provideTableMetadata(tableName, clusterName, connection)); } return catalogMetadataBuilder.build(); } private  MongoMetadataEngine(MongoConnectionHandler connectionHandler); static MongoMetadataEngine getInstance(MongoConnectionHandler connectionHandler);  }