Skip to content

Commit

Permalink
Added exposure of the data manager id through the context. (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnhatch authored Mar 1, 2024
1 parent f37ad1f commit d149d27
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,12 @@ public List<DataManagerPlan> retrievePlans() {
return simulation.retrievePlansForDataManager(dataManagerId);
}

/**
* Returns the DataManagerId of the data manager assigned to this instance of
* the data manager context.
*/
public DataManagerId getDataManagerId() {
return dataManagerId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1073,4 +1073,44 @@ private void planRetrievalSimCloseSubscribe(DataManagerContext context, List<Dat
assertEquals(expectedPlans.size(), plans.size());
assertEquals(expectedPlans, plans);
}

@Test
@UnitTestMethod(target = DataManagerContext.class, name = "getDataManagerId", args = {})
public void testGetDataManagerId() {

TestPluginData.Builder pluginDataBuilder = TestPluginData.builder();

pluginDataBuilder.addTestDataManager("dm1", () -> new TestDataManager1());
pluginDataBuilder.addTestDataManager("dm2", () -> new TestDataManager2());
pluginDataBuilder.addTestDataManager("dm3", () -> new TestDataManager3());

/*
* The TestPlugin already contains a data manager that will be added to the
* simulation ahead of the ones above, so the numbering will start with 1.
*/

pluginDataBuilder.addTestDataManagerPlan("dm1", new TestDataManagerPlan(0, (context) -> {
assertEquals(new DataManagerId(1), context.getDataManagerId());
}));

pluginDataBuilder.addTestDataManagerPlan("dm2", new TestDataManagerPlan(0, (context) -> {
assertEquals(new DataManagerId(2), context.getDataManagerId());
}));

pluginDataBuilder.addTestDataManagerPlan("dm3", new TestDataManagerPlan(0, (context) -> {
assertEquals(new DataManagerId(3), context.getDataManagerId());
}));

// build the plugin
TestPluginData testPluginData = pluginDataBuilder.build();
Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData);

TestOutputConsumer testOutputConsumer = new TestOutputConsumer();
// run the simulation
Simulation.builder()//
.addPlugin(testPlugin)//
.setOutputConsumer(testOutputConsumer).build()//
.execute();//

}
}

0 comments on commit d149d27

Please sign in to comment.