Skip to content

Commit

Permalink
Fully updated to refactored Command handler
Browse files Browse the repository at this point in the history
  • Loading branch information
VigneshSK17 committed Jan 14, 2025
1 parent c4ded5f commit 0c55e20
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,11 @@ private void handlePropertiesCommand() {

/** Handles the "UPDATE" command. */
private void handleUpdateCommand() {
if (line.hasOption(GravitinoOptions.ENABLE) && line.hasOption(GravitinoOptions.DISABLE)) {
System.err.println(ErrorMessages.INVALID_ENABLE_DISABLE);
Main.exit(-1);
}
if (line.hasOption(GravitinoOptions.ENABLE)) {
boolean enableMetalake = line.hasOption(GravitinoOptions.ALL);
boolean disable = line.hasOption(GravitinoOptions.DISABLE);
gravitinoCommandLine
.newCatalogEnable(url, ignore, metalake, catalog, enableMetalake)
.newCatalogEnable(url, ignore, metalake, catalog, disable, enableMetalake)
.validate()
.handle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,11 @@ private void handlePropertiesCommand() {

/** Handles the "UPDATE" command. */
private void handleUpdateCommand() {
if (line.hasOption(GravitinoOptions.ENABLE) && line.hasOption(GravitinoOptions.DISABLE)) {
System.err.println(ErrorMessages.INVALID_ENABLE_DISABLE);
Main.exit(-1);
}
if (line.hasOption(GravitinoOptions.ENABLE)) {
boolean enableAllCatalogs = line.hasOption(GravitinoOptions.ALL);
boolean disable = line.hasOption(GravitinoOptions.DISABLE);
gravitinoCommandLine
.newMetalakeEnable(url, ignore, metalake, enableAllCatalogs)
.newMetalakeEnable(url, ignore, metalake, disable, enableAllCatalogs)
.validate()
.handle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,30 @@ void testDisableCatalogCommand() {
@SuppressWarnings("DefaultCharset")
void testCatalogWithDisableAndEnableOptions() {
Main.useExit = false;
CatalogEnable mockCatalogEnable =
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
when(mockCommandLine.hasOption(GravitinoOptions.NAME)).thenReturn(true);
when(mockCommandLine.getOptionValue(GravitinoOptions.NAME)).thenReturn("catalog");
when(mockCommandLine.hasOption(GravitinoOptions.DISABLE)).thenReturn(true);
when(mockCommandLine.hasOption(GravitinoOptions.ENABLE)).thenReturn(true);

GravitinoCommandLine commandLine =
spy(
new CatalogEnable(
GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "catalog", true, false));
new GravitinoCommandLine(
mockCommandLine, mockOptions, CommandEntities.CATALOG, CommandActions.UPDATE));

assertThrows(RuntimeException.class, mockCatalogEnable::validate);
assertThrows(
RuntimeException.class,
() ->
commandLine
.newCatalogEnable(
GravitinoCommandLine.DEFAULT_URL,
false,
"metalake_demo",
"catalog",
true,
false)
.validate());
String errOutput = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim();
Assertions.assertEquals(ErrorMessages.INVALID_ENABLE_DISABLE, errOutput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,23 @@ void testDisableMetalakeCommand() {
@SuppressWarnings("DefaultCharset")
void testMetalakeWithDisableAndEnableOptions() {
Main.useExit = false;
MetalakeEnable mockMetalakeEnable =
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
when(mockCommandLine.hasOption(GravitinoOptions.DISABLE)).thenReturn(true);
when(mockCommandLine.hasOption(GravitinoOptions.ENABLE)).thenReturn(true);

GravitinoCommandLine commandLine =
spy(
new MetalakeEnable(
GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", true, false));
new GravitinoCommandLine(
mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.UPDATE));

assertThrows(RuntimeException.class, mockMetalakeEnable::validate);
assertThrows(
RuntimeException.class,
() ->
commandLine
.newMetalakeEnable(
GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", true, false)
.validate());
String errOutput = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim();
Assertions.assertEquals(ErrorMessages.INVALID_ENABLE_DISABLE, errOutput);
}
Expand Down

0 comments on commit 0c55e20

Please sign in to comment.