Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ClusterVO updateClusterConfig(UpdateConfigDTO command) {
}

if (command.getFlushDiskType() != null) {
config.setFlushDiskType(FlushDiskType.valueOf(command.getFlushDiskType()));
config.setFlushDiskType(parseFlushDiskType(command.getFlushDiskType()));
}
if (command.getAutoCreateTopicEnable() != null) {
config.setAutoCreateTopicEnable(command.getAutoCreateTopicEnable());
Expand Down Expand Up @@ -95,6 +95,14 @@ public ClusterVO updateClusterConfig(UpdateConfigDTO command) {
return cluster;
}

private FlushDiskType parseFlushDiskType(String value) {
try {
return FlushDiskType.valueOf(value);
} catch (IllegalArgumentException ex) {
throw new BusinessException(400, "Invalid flushDiskType: " + value);
}
}

public boolean restartBroker(String clusterId, String brokerName) {
log.info("Restarting broker: {} in cluster: {}", brokerName, clusterId);
clusterRepository.findById(clusterId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -210,6 +211,22 @@ void updateConfigShouldThrowWhenClusterNotFound() {
.hasMessageContaining("Cluster not found: missing");
}

@Test
void updateConfigShouldRejectInvalidFlushDiskType() {
when(clusterRepository.findById("cluster-1")).thenReturn(Optional.of(sampleCluster));

UpdateConfigDTO command = UpdateConfigDTO.builder()
.id("cluster-1")
.flushDiskType("INVALID_FLUSH")
.build();

assertThatThrownBy(() -> clusterService.updateClusterConfig(command))
.isInstanceOf(BusinessException.class)
.hasMessageContaining("Invalid flushDiskType: INVALID_FLUSH")
.satisfies(ex -> assertThat(((BusinessException) ex).getCode()).isEqualTo(400));
verify(clusterRepository, never()).updateConfig(eq("cluster-1"), any(ClusterConfigVO.class));
}

@Test
void updateConfigShouldCreateConfigWhenNull() {
ClusterVO clusterWithNullConfig = ClusterVO.builder()
Expand Down
Loading