Skip to content

Commit

Permalink
feat(emulator): init command
Browse files Browse the repository at this point in the history
  • Loading branch information
jeqo committed Jul 21, 2022
1 parent 77be6c6 commit fa09b03
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
31 changes: 30 additions & 1 deletion emulator/src/main/java/kafka/cli/emulator/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
""",
versionProvider = Cli.VersionProviderWithConfigProvider.class,
mixinStandardHelpOptions = true,
subcommands = { Cli.RecordCommand.class, Cli.ReplayCommand.class }
subcommands = { Cli.InitCommand.class, Cli.RecordCommand.class, Cli.ReplayCommand.class }
)
public class Cli implements Callable<Integer> {

Expand All @@ -45,6 +45,35 @@ public Integer call() {
return 0;
}

@CommandLine.Command(
name = "init",
description = """
Initialize emualator archive file
"""
)
static class InitCommand implements Callable<Integer> {

@CommandLine.Parameters(
index = "0",
description = """
Path to emulator archive""",
defaultValue = "./kfk-emulator.db"
)
Path archivePath;

@Override
public Integer call() {
try {
final var store = new ArchiveStore.SqliteArchiveLoader(archivePath);
final var emu = new KafkaEmulator(store);
emu.init();
return 0;
} catch (Exception e) {
e.printStackTrace();
return 1;
}
}
}
@CommandLine.Command(
name = "record",
description = """
Expand Down
5 changes: 5 additions & 0 deletions emulator/src/main/java/kafka/cli/emulator/KafkaEmulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public KafkaEmulator(ArchiveStore archiveLoader) {
this.archiveLoader = archiveLoader;
}

public void init() {
final var archive = EmulatorArchive.create();
archiveLoader.save(archive);
}

/**
* Read and package topics records into an archive.
*
Expand Down

0 comments on commit fa09b03

Please sign in to comment.