@Test public void testProgramDatasetMapping() throws Exception { UsageDataset usageDataset = getUsageDataset("testProgramDatasetMapping"); // Add mappings usageDataset.register(flow11, datasetInstance1); usageDataset.register(flow11, datasetInstance3); usageDataset.register(flow12, datasetInstance2); usageDataset.register(service11, datasetInstance1); usageDataset.register(flow21, datasetInstance2); usageDataset.register(service21, datasetInstance1); // Verify program mappings Assert.assertEquals( ImmutableSet.of(datasetInstance1, datasetInstance3), usageDataset.getDatasets(flow11)); Assert.assertEquals(ImmutableSet.of(datasetInstance2), usageDataset.getDatasets(flow12)); Assert.assertEquals(ImmutableSet.of(datasetInstance1), usageDataset.getDatasets(service11)); Assert.assertEquals(ImmutableSet.of(datasetInstance2), usageDataset.getDatasets(flow21)); Assert.assertEquals(ImmutableSet.of(datasetInstance1), usageDataset.getDatasets(service21)); // Verify app mappings Assert.assertEquals( ImmutableSet.of(datasetInstance1, datasetInstance2, datasetInstance3), usageDataset.getDatasets(flow11.getApplication())); Assert.assertEquals( ImmutableSet.of(datasetInstance1, datasetInstance2), usageDataset.getDatasets(flow21.getApplication())); // Verify dataset mappings Assert.assertEquals( ImmutableSet.of(flow11, service11, service21), usageDataset.getPrograms(datasetInstance1)); Assert.assertEquals( ImmutableSet.of(flow12, flow21), usageDataset.getPrograms(datasetInstance2)); Assert.assertEquals(ImmutableSet.of(flow11), usageDataset.getPrograms(datasetInstance3)); // --------- Delete app1 ----------- usageDataset.unregister(flow11.getApplication()); // There should be no mappings for programs of app1 now Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow11)); Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow12)); Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(service11)); Assert.assertEquals(ImmutableSet.of(datasetInstance2), usageDataset.getDatasets(flow21)); Assert.assertEquals(ImmutableSet.of(datasetInstance1), usageDataset.getDatasets(service21)); // Verify app mappings Assert.assertEquals( ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow11.getApplication())); Assert.assertEquals( ImmutableSet.of(datasetInstance1, datasetInstance2), usageDataset.getDatasets(flow21.getApplication())); // Verify dataset mappings Assert.assertEquals(ImmutableSet.of(service21), usageDataset.getPrograms(datasetInstance1)); Assert.assertEquals(ImmutableSet.of(flow21), usageDataset.getPrograms(datasetInstance2)); Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(datasetInstance3)); }
@Test public void testAllMappings() throws Exception { UsageDataset usageDataset = getUsageDataset("testAllMappings"); // Add mappings usageDataset.register(flow11, datasetInstance1); usageDataset.register(service21, datasetInstance3); usageDataset.register(adapter1, datasetInstance1); usageDataset.register(adapter1, datasetInstance2); usageDataset.register(flow12, stream1); usageDataset.register(adapter2, stream2); // Verify app/adapter mappings Assert.assertEquals(ImmutableSet.of(datasetInstance1), usageDataset.getDatasets(flow11)); Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow12)); Assert.assertEquals(ImmutableSet.of(datasetInstance3), usageDataset.getDatasets(service21)); Assert.assertEquals( ImmutableSet.of(datasetInstance1, datasetInstance2), usageDataset.getDatasets(adapter1)); Assert.assertEquals(ImmutableSet.of(stream1), usageDataset.getStreams(flow12)); Assert.assertEquals(ImmutableSet.<Id.Stream>of(), usageDataset.getStreams(flow22)); Assert.assertEquals(ImmutableSet.of(stream2), usageDataset.getStreams(adapter2)); // Verify dataset/stream mappings Assert.assertEquals(ImmutableSet.of(flow11), usageDataset.getPrograms(datasetInstance1)); Assert.assertEquals(ImmutableSet.of(adapter1), usageDataset.getAdapters(datasetInstance1)); Assert.assertEquals(ImmutableSet.of(flow12), usageDataset.getPrograms(stream1)); Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(stream2)); Assert.assertEquals(ImmutableSet.of(adapter2), usageDataset.getAdapters(stream2)); // --------- Delete app1 ----------- usageDataset.unregister(flow11.getApplication()); // Verify app/adapter mappings Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow11)); Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow12)); Assert.assertEquals(ImmutableSet.of(datasetInstance3), usageDataset.getDatasets(service21)); Assert.assertEquals( ImmutableSet.of(datasetInstance1, datasetInstance2), usageDataset.getDatasets(adapter1)); Assert.assertEquals(ImmutableSet.<Id.Stream>of(), usageDataset.getStreams(flow12)); Assert.assertEquals(ImmutableSet.<Id.Stream>of(), usageDataset.getStreams(flow22)); Assert.assertEquals(ImmutableSet.of(stream2), usageDataset.getStreams(adapter2)); // Verify dataset/stream mappings Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(datasetInstance1)); Assert.assertEquals(ImmutableSet.of(adapter1), usageDataset.getAdapters(datasetInstance1)); Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(stream1)); Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(stream2)); Assert.assertEquals(ImmutableSet.of(adapter2), usageDataset.getAdapters(stream2)); // --------- Delete adapter1 ----------- usageDataset.unregister(adapter1); // Verify app/adapter mappings Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow11)); Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow12)); Assert.assertEquals(ImmutableSet.of(datasetInstance3), usageDataset.getDatasets(service21)); Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(adapter1)); Assert.assertEquals(ImmutableSet.<Id.Stream>of(), usageDataset.getStreams(flow12)); Assert.assertEquals(ImmutableSet.<Id.Stream>of(), usageDataset.getStreams(flow22)); Assert.assertEquals(ImmutableSet.of(stream2), usageDataset.getStreams(adapter2)); // Verify dataset/stream mappings Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(datasetInstance1)); Assert.assertEquals(ImmutableSet.<Id.Adapter>of(), usageDataset.getAdapters(datasetInstance1)); Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(stream1)); Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(stream2)); Assert.assertEquals(ImmutableSet.of(adapter2), usageDataset.getAdapters(stream2)); // --------- Delete adapter2 ----------- usageDataset.unregister(adapter2); // Verify app/adapter mappings Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow11)); Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow12)); Assert.assertEquals(ImmutableSet.of(datasetInstance3), usageDataset.getDatasets(service21)); Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(adapter1)); Assert.assertEquals(ImmutableSet.<Id.Stream>of(), usageDataset.getStreams(flow12)); Assert.assertEquals(ImmutableSet.<Id.Stream>of(), usageDataset.getStreams(flow22)); Assert.assertEquals(ImmutableSet.<Id.Stream>of(), usageDataset.getStreams(adapter2)); // Verify dataset/stream mappings Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(datasetInstance1)); Assert.assertEquals(ImmutableSet.<Id.Adapter>of(), usageDataset.getAdapters(datasetInstance1)); Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(stream1)); Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(stream2)); Assert.assertEquals(ImmutableSet.<Id.Adapter>of(), usageDataset.getAdapters(stream2)); // --------- Delete app2 ----------- usageDataset.unregister(flow21.getApplication()); // Verify app/adapter mappings Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow11)); Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(flow12)); Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(service21)); Assert.assertEquals(ImmutableSet.<Id.DatasetInstance>of(), usageDataset.getDatasets(adapter1)); Assert.assertEquals(ImmutableSet.<Id.Stream>of(), usageDataset.getStreams(flow12)); Assert.assertEquals(ImmutableSet.<Id.Stream>of(), usageDataset.getStreams(flow22)); Assert.assertEquals(ImmutableSet.<Id.Stream>of(), usageDataset.getStreams(adapter2)); // Verify dataset/stream mappings Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(datasetInstance1)); Assert.assertEquals(ImmutableSet.<Id.Adapter>of(), usageDataset.getAdapters(datasetInstance1)); Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(stream1)); Assert.assertEquals(ImmutableSet.<Id.Program>of(), usageDataset.getPrograms(stream2)); Assert.assertEquals(ImmutableSet.<Id.Adapter>of(), usageDataset.getAdapters(stream2)); }