forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UnsafePlainActionFuture would allow any threads to do unsafe completes when using the one-arg constructor, fixed.
- Loading branch information
1 parent
9185056
commit caa55f5
Showing
2 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
server/src/test/java/org/elasticsearch/action/support/UnsafePlainActionFutureTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.support; | ||
|
||
import org.elasticsearch.common.util.concurrent.EsExecutors; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class UnsafePlainActionFutureTests extends ESTestCase { | ||
|
||
public void testOneArg() { | ||
String unsafeExecutorName = "unsafe-executor"; | ||
String otherExecutorName = "other-executor"; | ||
UnsafePlainActionFuture<?> future = new UnsafePlainActionFuture<Void>(unsafeExecutorName); | ||
Thread other1 = getThread(otherExecutorName); | ||
Thread other2 = getThread(otherExecutorName); | ||
assertFalse(future.allowedExecutors(other1, other2)); | ||
Thread unsafe1 = getThread(unsafeExecutorName); | ||
Thread unsafe2 = getThread(unsafeExecutorName); | ||
assertTrue(future.allowedExecutors(unsafe1, unsafe2)); | ||
|
||
assertTrue(future.allowedExecutors(unsafe1, other1)); | ||
} | ||
|
||
public void testTwoArg() { | ||
String unsafeExecutorName1 = "unsafe-executor-1"; | ||
String unsafeExecutorName2 = "unsafe-executor-2"; | ||
String otherExecutorName = "other-executor"; | ||
UnsafePlainActionFuture<?> future = new UnsafePlainActionFuture<Void>(unsafeExecutorName1, unsafeExecutorName2); | ||
Thread other1 = getThread(otherExecutorName); | ||
Thread other2 = getThread(otherExecutorName); | ||
assertFalse(future.allowedExecutors(other1, other2)); | ||
Thread unsafe1Thread1 = getThread(unsafeExecutorName1); | ||
Thread unsafe2Thread1 = getThread(unsafeExecutorName2); | ||
Thread unsafe1Thread2 = getThread(unsafeExecutorName1); | ||
Thread unsafe2Thread2 = getThread(unsafeExecutorName2); | ||
assertTrue(future.allowedExecutors(unsafe1Thread1, unsafe1Thread2)); | ||
assertTrue(future.allowedExecutors(unsafe2Thread1, unsafe2Thread2)); | ||
|
||
assertTrue(future.allowedExecutors(unsafe1Thread1, unsafe2Thread2)); | ||
assertTrue(future.allowedExecutors(unsafe2Thread1, other1)); | ||
assertTrue(future.allowedExecutors(other1, unsafe2Thread2)); | ||
} | ||
|
||
private static Thread getThread(String executorName) { | ||
Thread t = new Thread("[" + executorName + "][]"); | ||
assertThat(EsExecutors.executorName(t), equalTo(executorName)); | ||
return t; | ||
} | ||
} |