Skip to content

Commit

Permalink
Show compute nodes from repository (#34371)
Browse files Browse the repository at this point in the history
  • Loading branch information
menghaoranss authored Jan 16, 2025
1 parent 32b1aa7 commit 7ffbdca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Collection<LocalDataQueryResultRow> getRows(final ShowComputeNodesStateme
String modeType = contextManager.getComputeNodeInstanceContext().getModeConfiguration().getType();
return "Standalone".equals(modeType)
? Collections.singleton(buildRow(contextManager.getComputeNodeInstanceContext().getInstance(), modeType))
: contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry().getAllClusterInstances().stream().map(each -> buildRow(each, modeType)).collect(Collectors.toList());
: contextManager.getPersistServiceFacade().getComputeNodePersistService().loadAllInstances().stream().map(each -> buildRow(each, modeType)).collect(Collectors.toList());
}

private LocalDataQueryResultRow buildRow(final ComputeNodeInstance instance, final String modeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ void assertExecuteWithStandaloneMode() {
@Test
void assertExecuteWithClusterMode() {
ShowComputeNodesExecutor executor = new ShowComputeNodesExecutor();
ContextManager contextManager = mock(ContextManager.class);
ComputeNodeInstanceContext computeNodeInstanceContext = createClusterInstanceContext();
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
ComputeNodeInstanceContext computeNodeInstanceContext = createClusterInstanceContext(contextManager);
when(contextManager.getComputeNodeInstanceContext()).thenReturn(computeNodeInstanceContext);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowComputeNodesStatement.class), contextManager);
assertThat(actual.size(), is(1));
Expand All @@ -92,14 +92,15 @@ private ComputeNodeInstanceContext createStandaloneInstanceContext() {
return result;
}

private ComputeNodeInstanceContext createClusterInstanceContext() {
private ComputeNodeInstanceContext createClusterInstanceContext(final ContextManager contextManager) {
ComputeNodeInstanceContext result = mock(ComputeNodeInstanceContext.class, RETURNS_DEEP_STUBS);
when(result.getModeConfiguration()).thenReturn(new ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class)));
ComputeNodeInstance computeNodeInstance = mock(ComputeNodeInstance.class, RETURNS_DEEP_STUBS);
when(computeNodeInstance.getMetaData()).thenReturn(new ProxyInstanceMetaData("foo", "127.0.0.1@3309", "foo_version"));
when(computeNodeInstance.getState()).thenReturn(new InstanceStateContext());
when(computeNodeInstance.getWorkerId()).thenReturn(1);
when(result.getClusterInstanceRegistry().getAllClusterInstances()).thenReturn(Collections.singleton(computeNodeInstance));
when(contextManager.getPersistServiceFacade().getComputeNodePersistService().loadAllInstances()).thenReturn(Collections.singleton(computeNodeInstance));
return result;
}
}

0 comments on commit 7ffbdca

Please sign in to comment.