Skip to content
Merged
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 @@ -66,6 +66,7 @@ public void cancel() {

if (statementState.equals(StatementState.SUCCESS)
|| statementState.equals(StatementState.FAILED)
|| statementState.equals(StatementState.TIMEOUT)
|| statementState.equals(StatementState.CANCELLED)) {
String errorMsg =
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum StatementState {
RUNNING("running"),
SUCCESS("success"),
FAILED("failed"),
TIMEOUT("timeout"),
CANCELLED("cancelled");

private final String state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void openFailedBecauseConflict() {
}

@Test
public void cancelNotExistStatement() {
public void cancelNotExistStatement_throwsException() {
StatementId stId = new StatementId("statementId");
Statement st = buildStatement(stId);
st.open();
Expand All @@ -141,8 +141,6 @@ public void cancelFailedBecauseOfConflict() {
statementStorageService.updateStatementState(st.getStatementModel(), CANCELLED);

assertEquals(StatementState.CANCELLED, running.getStatementState());

// cancel conflict
IllegalStateException exception = assertThrows(IllegalStateException.class, st::cancel);
assertEquals(
String.format(
Expand All @@ -151,55 +149,36 @@ public void cancelFailedBecauseOfConflict() {
}

@Test
public void cancelSuccessStatementFailed() {
StatementId stId = new StatementId("statementId");
Statement st = createStatement(stId);

// update to running state
StatementModel model = st.getStatementModel();
st.setStatementModel(
StatementModel.copyWithState(
st.getStatementModel(), StatementState.SUCCESS, model.getMetadata()));

// cancel conflict
IllegalStateException exception = assertThrows(IllegalStateException.class, st::cancel);
assertEquals(
String.format("can't cancel statement in success state. statement: %s.", stId),
exception.getMessage());
public void cancelCancelledStatement_throwsException() {
testCancelThrowsExceptionGivenStatementState(StatementState.CANCELLED);
}

@Test
public void cancelFailedStatementFailed() {
StatementId stId = new StatementId("statementId");
Statement st = createStatement(stId);

// update to running state
StatementModel model = st.getStatementModel();
st.setStatementModel(
StatementModel.copyWithState(
st.getStatementModel(), StatementState.FAILED, model.getMetadata()));
public void cancelSuccessStatement_throwsException() {
testCancelThrowsExceptionGivenStatementState(StatementState.SUCCESS);
}

// cancel conflict
IllegalStateException exception = assertThrows(IllegalStateException.class, st::cancel);
assertEquals(
String.format("can't cancel statement in failed state. statement: %s.", stId),
exception.getMessage());
@Test
public void cancelFailedStatement_throwsException() {
testCancelThrowsExceptionGivenStatementState(StatementState.FAILED);
}

@Test
public void cancelCancelledStatementFailed() {
public void cancelTimeoutStatement_throwsException() {
testCancelThrowsExceptionGivenStatementState(StatementState.TIMEOUT);
}

private void testCancelThrowsExceptionGivenStatementState(StatementState state) {
StatementId stId = new StatementId("statementId");
Statement st = createStatement(stId);

// update to running state
StatementModel model = st.getStatementModel();
st.setStatementModel(
StatementModel.copyWithState(st.getStatementModel(), CANCELLED, model.getMetadata()));
StatementModel.copyWithState(st.getStatementModel(), state, model.getMetadata()));

// cancel conflict
IllegalStateException exception = assertThrows(IllegalStateException.class, st::cancel);
assertEquals(
String.format("can't cancel statement in cancelled state. statement: %s.", stId),
String.format("can't cancel statement in %s state. statement: %s.", state.getState(), stId),
exception.getMessage());
}

Expand Down