mirror of https://github.com/apache/kafka.git
KAFKA-16409: DeleteRecordsCommand should use standard exception handling (#15586)
DeleteRecordsCommand should use standard exception handling Reviewers: Luke Chen <showuon@gmail.com>
This commit is contained in:
parent
ad960635a9
commit
fa1cf7975e
|
@ -24,6 +24,7 @@ import org.apache.kafka.clients.admin.Admin;
|
|||
import org.apache.kafka.clients.admin.DeleteRecordsResult;
|
||||
import org.apache.kafka.clients.admin.RecordsToDelete;
|
||||
import org.apache.kafka.common.TopicPartition;
|
||||
import org.apache.kafka.common.utils.Exit;
|
||||
import org.apache.kafka.common.utils.Utils;
|
||||
import org.apache.kafka.server.common.AdminCommandFailedException;
|
||||
import org.apache.kafka.server.common.AdminOperationException;
|
||||
|
@ -61,7 +62,18 @@ public class DeleteRecordsCommand {
|
|||
private static final DecodeJson.DecodeString STRING = new DecodeJson.DecodeString();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Exit.exit(mainNoExit(args));
|
||||
}
|
||||
|
||||
static int mainNoExit(String... args) {
|
||||
try {
|
||||
execute(args, System.out);
|
||||
return 0;
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
System.err.println(Utils.stackTrace(e));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static Map<TopicPartition, List<Long>> parseOffsetJsonStringWithoutDedup(String jsonData) throws JsonProcessingException {
|
||||
|
|
|
@ -120,7 +120,11 @@ public class DeleteRecordsCommandTest {
|
|||
class DeleteRecordsCommandUnitTest {
|
||||
@Test
|
||||
public void testOffsetFileNotExists() {
|
||||
assertThrows(IOException.class, () -> DeleteRecordsCommand.main(new String[]{
|
||||
assertThrows(IOException.class, () -> DeleteRecordsCommand.execute(new String[]{
|
||||
"--bootstrap-server", "localhost:9092",
|
||||
"--offset-json-file", "/not/existing/file"
|
||||
}, System.out));
|
||||
assertEquals(1, DeleteRecordsCommand.mainNoExit(new String[]{
|
||||
"--bootstrap-server", "localhost:9092",
|
||||
"--offset-json-file", "/not/existing/file"
|
||||
}));
|
||||
|
@ -128,7 +132,12 @@ class DeleteRecordsCommandUnitTest {
|
|||
|
||||
@Test
|
||||
public void testCommandConfigNotExists() {
|
||||
assertThrows(NoSuchFileException.class, () -> DeleteRecordsCommand.main(new String[] {
|
||||
assertThrows(NoSuchFileException.class, () -> DeleteRecordsCommand.execute(new String[] {
|
||||
"--bootstrap-server", "localhost:9092",
|
||||
"--offset-json-file", "/not/existing/file",
|
||||
"--command-config", "/another/not/existing/file"
|
||||
}, System.out));
|
||||
assertEquals(1, DeleteRecordsCommand.mainNoExit(new String[] {
|
||||
"--bootstrap-server", "localhost:9092",
|
||||
"--offset-json-file", "/not/existing/file",
|
||||
"--command-config", "/another/not/existing/file"
|
||||
|
|
Loading…
Reference in New Issue