@Test public void testPreferDatasourceResults() throws Exception { Map<String, Datasource> nameToDatasource = new HashMap<>(); nameToDatasource.put("mock", new MockDatasource("mock", List.of("column"), List.of(new MockDataset("ds", "column", "value")))); nameToDatasource.put("mock2", new MockDatasource("mock2", List.of("column"), List.of(new MockDataset("ds", "column", "value3"), new MockDataset("ds1", "column", "value4")))); Datasource ds = new PreferDatasource(nameToDatasource, new ConfigThingy("", "NAME \"prefer\" SOURCE \"mock\" OVER \"mock2\""), null); QueryResults results = ds.getDatasetsByKey(List.of("ds")); assertFalse(results.isEmpty()); assertEquals(1, results.size()); Iterator<Dataset> iter = results.iterator(); assertTrue(iter.hasNext()); assertThrows(UnsupportedOperationException.class, () -> iter.remove()); Dataset data = iter.next(); assertEquals("value", data.get("column")); assertFalse(iter.hasNext()); assertThrows(NoSuchElementException.class, () -> iter.next()); results = ds.getDatasetsByKey(List.of("unknown")); assertTrue(results.isEmpty()); results = ds.getDatasetsByKey(List.of("ds1")); Iterator<Dataset> iter2 = results.iterator(); data = iter2.next(); assertEquals("value4", data.get("column")); }
@Override public QueryResults getDatasetsByKey(Collection<String> keys) { return new QueryResultsOverride(source2.getDatasetsByKey(keys), source1.getDatasetsByKey(keys), source1); }
PreferDatasource extends Datasource { @Override public QueryResults getDatasetsByKey(Collection<String> keys) { return new QueryResultsOverride(source2.getDatasetsByKey(keys), source1.getDatasetsByKey(keys), source1); } }
PreferDatasource extends Datasource { @Override public QueryResults getDatasetsByKey(Collection<String> keys) { return new QueryResultsOverride(source2.getDatasetsByKey(keys), source1.getDatasetsByKey(keys), source1); } PreferDatasource(Map<String, Datasource> nameToDatasource,
      ConfigThingy sourceDesc, URL context); }
PreferDatasource extends Datasource { @Override public QueryResults getDatasetsByKey(Collection<String> keys) { return new QueryResultsOverride(source2.getDatasetsByKey(keys), source1.getDatasetsByKey(keys), source1); } PreferDatasource(Map<String, Datasource> nameToDatasource,
      ConfigThingy sourceDesc, URL context); @Override List<String> getSchema(); @Override QueryResults getDatasetsByKey(Collection<String> keys); @Override QueryResults getContents(); @Override QueryResults find(List<QueryPart> query); @Override String getName(); }
PreferDatasource extends Datasource { @Override public QueryResults getDatasetsByKey(Collection<String> keys) { return new QueryResultsOverride(source2.getDatasetsByKey(keys), source1.getDatasetsByKey(keys), source1); } PreferDatasource(Map<String, Datasource> nameToDatasource,
      ConfigThingy sourceDesc, URL context); @Override List<String> getSchema(); @Override QueryResults getDatasetsByKey(Collection<String> keys); @Override QueryResults getContents(); @Override QueryResults find(List<QueryPart> query); @Override String getName();  }