Skip to content

Commit

Permalink
Refactor ProcessListChangedSubscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Dec 29, 2024
1 parent 9a266a5 commit 16c0c3d
Showing 1 changed file with 1 addition and 17 deletions.
Original file line number Diff line number Diff line change
@@ -17,18 +17,14 @@

package org.apache.shardingsphere.mode.manager.standalone.persist.service;

import org.apache.shardingsphere.infra.executor.sql.process.Process;
import org.apache.shardingsphere.infra.executor.sql.process.ProcessRegistry;
import org.apache.shardingsphere.test.mock.AutoMockExtension;
import org.apache.shardingsphere.test.mock.StaticMockSettings;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -51,19 +47,7 @@ void assertGetProcessList() {
void assertKillProcess() throws SQLException {
ProcessRegistry processRegistry = mock(ProcessRegistry.class);
when(ProcessRegistry.getInstance()).thenReturn(processRegistry);
Process process = mock(Process.class);
Statement statement = mock(Statement.class);
when(process.getProcessStatements()).thenReturn(Collections.singletonMap(1, statement));
when(processRegistry.get("foo_id")).thenReturn(process);
processPersistService.killProcess("foo_id");
verify(statement).cancel();
}

@Test
void assertKillProcessWithNotExistedProcessId() {
ProcessRegistry processRegistry = mock(ProcessRegistry.class);
when(ProcessRegistry.getInstance()).thenReturn(processRegistry);
when(processRegistry.get("foo_id")).thenReturn(null);
assertDoesNotThrow(() -> processPersistService.killProcess("foo_id"));
verify(ProcessRegistry.getInstance()).kill("foo_id");
}
}

0 comments on commit 16c0c3d

Please sign in to comment.