Skip to content

Commit

Permalink
Rename terminate query to kill query
Browse files Browse the repository at this point in the history
  • Loading branch information
boggle authored and systay committed Sep 14, 2016
1 parent 6c8be34 commit c54cfa3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Expand Up @@ -140,24 +140,24 @@ public Stream<QueryStatusResult> listQueries() throws InvalidArgumentsException,
.map( this::queryStatusResult );
}

@Procedure( name = "dbms.terminateQuery", mode = DBMS )
public Stream<QueryTerminationResult> terminateQuery( @Name( "id" ) String idText )
@Procedure( name = "dbms.killQuery", mode = DBMS )
public Stream<QueryTerminationResult> killQuery( @Name( "id" ) String idText )
throws InvalidArgumentsException, IOException
{
long queryId = parseQueryId( idText ).kernelQueryId();
Set<Pair<KernelTransactionHandle,ExecutingQuery>> executingQueries =
getKernelTransactions().activeTransactions( tx -> executingQueriesWithId( queryId, tx ) );
return executingQueries
.stream()
.map(this::terminateQueryTransaction);
.map(this::killQueryTransaction);
}

private Stream<ExecutingQuery> executingQueriesWithId( long id, KernelTransactionHandle txHandle )
{
return txHandle.executingQueries().filter( q -> q.kernelQueryId() == id );
}

private QueryTerminationResult terminateQueryTransaction( Pair<KernelTransactionHandle, ExecutingQuery> pair )
private QueryTerminationResult killQueryTransaction( Pair<KernelTransactionHandle, ExecutingQuery> pair )
{
ExecutingQuery query = pair.other();
if ( isAdminEnterpriseAuthSubject() || authSubject.hasUsername( query.authSubjectName() ) )
Expand Down
Expand Up @@ -251,7 +251,7 @@ public void shouldListQueriesEvenIfUsingPeriodicCommit() throws Throwable
//---------- terminate query -----------

@Test
public void shouldTerminateQueryAsAdmin() throws Throwable
public void shouldKillQueryAsAdmin() throws Throwable
{
DoubleLatch latch = new DoubleLatch( 3 );
ThreadedTransactionCreate<S> read1 = new ThreadedTransactionCreate<>( neo, latch );
Expand All @@ -264,7 +264,7 @@ public void shouldTerminateQueryAsAdmin() throws Throwable

assertSuccess(
adminSubject,
"CALL dbms.terminateQuery('" + id1 + "') YIELD username " +
"CALL dbms.killQuery('" + id1 + "') YIELD username " +
"RETURN count(username) AS count, username", r ->
{
List<Map<String,Object>> actual = r.stream().collect( toList() );
Expand All @@ -286,7 +286,7 @@ public void shouldTerminateQueryAsAdmin() throws Throwable
}

@Test
public void shouldTerminateQueryAsUser() throws Throwable
public void shouldKillQueryAsUser() throws Throwable
{
DoubleLatch latch = new DoubleLatch( 3 );
ThreadedTransactionCreate<S> read = new ThreadedTransactionCreate<>( neo, latch );
Expand All @@ -299,7 +299,7 @@ public void shouldTerminateQueryAsUser() throws Throwable

assertSuccess(
readSubject,
"CALL dbms.terminateQuery('" + id1 + "') YIELD username " +
"CALL dbms.killQuery('" + id1 + "') YIELD username " +
"RETURN count(username) AS count, username", r ->
{
List<Map<String,Object>> actual = r.stream().collect( toList() );
Expand All @@ -321,12 +321,12 @@ public void shouldTerminateQueryAsUser() throws Throwable
}

@Test
public void shouldSelfTerminateQuery() throws Throwable
public void shouldSelfKillQuery() throws Throwable
{
String result = neo.executeQuery(
readSubject,
"WITH 'Hello' AS marker CALL dbms.listQueries() YIELD queryId AS id, query " +
"WITH * WHERE query CONTAINS 'Hello' CALL dbms.terminateQuery(id) YIELD username " +
"WITH * WHERE query CONTAINS 'Hello' CALL dbms.killQuery(id) YIELD username " +
"RETURN count(username) AS count, username",
Collections.emptyMap(),
r -> {}
Expand Down Expand Up @@ -354,7 +354,7 @@ public void shouldFailToTerminateOtherUsersQuery() throws Throwable
String id1 = extractQueryId( q1 );
assertFail(
writeSubject,
"CALL dbms.terminateQuery('" + id1 + "') YIELD username RETURN *",
"CALL dbms.killQuery('" + id1 + "') YIELD username RETURN *",
PERMISSION_DENIED
);
latch.finishAndWaitForAllToFinish();
Expand Down Expand Up @@ -405,7 +405,7 @@ public void shouldTerminateQueriesEvenIfUsingPeriodicCommit() throws Throwable

assertSuccess(
adminSubject,
"CALL dbms.terminateQuery('" + writeQueryId + "') YIELD username " +
"CALL dbms.killQuery('" + writeQueryId + "') YIELD username " +
"RETURN count(username) AS count, username", r ->
{
List<Map<String,Object>> actual = r.stream().collect( toList() );
Expand Down
Expand Up @@ -67,7 +67,7 @@ public void shouldNotListAnyQueriesIfNotAuthenticated()
}

@Test
public void shouldNotTerminateQueryIfNotAuthenticated() throws Throwable
public void shouldNotKillQueryIfNotAuthenticated() throws Throwable
{
EnterpriseAuthSubject authy = createFakeAnonymousEnterpriseAuthSubject();

Expand All @@ -83,7 +83,7 @@ public void shouldNotTerminateQueryIfNotAuthenticated() throws Throwable
try ( InternalTransaction tx = graph
.beginTransaction( KernelTransaction.Type.explicit, AuthSubject.ANONYMOUS ) )
{
graph.execute( tx, "CALL dbms.terminateQuery('" + id + "')", Collections.emptyMap() );
graph.execute( tx, "CALL dbms.killQuery('" + id + "')", Collections.emptyMap() );
throw new AssertionError( "Expected exception to be thrown" );
}
catch ( QueryExecutionException e )
Expand Down

0 comments on commit c54cfa3

Please sign in to comment.