|
|
@ -46,6 +46,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
|
import java.util.function.Consumer; |
|
|
|
import java.util.function.Consumer; |
|
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.google.common.collect.Lists; |
|
|
@ -316,6 +317,56 @@ public class NodeLocalConfigPermissioningControllerTest { |
|
|
|
.isTrue(); |
|
|
|
.isTrue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void whenCallingIsPermittedAndRemovingEntryInAnotherThreadShouldNotThrowException() |
|
|
|
|
|
|
|
throws InterruptedException { |
|
|
|
|
|
|
|
// Add a node to the allowlist
|
|
|
|
|
|
|
|
controller.addNodes(Lists.newArrayList(enode1)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Atomic flag to detect exceptions
|
|
|
|
|
|
|
|
AtomicBoolean exceptionOccurred = new AtomicBoolean(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a thread to call isPermitted
|
|
|
|
|
|
|
|
Thread isPermittedThread = |
|
|
|
|
|
|
|
new Thread( |
|
|
|
|
|
|
|
() -> { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
for (int i = 0; i < 1000; i++) { |
|
|
|
|
|
|
|
controller.isPermitted(enode1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
exceptionOccurred.set(true); |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a thread to modify the allowlist
|
|
|
|
|
|
|
|
Thread modifyAllowlistThread = |
|
|
|
|
|
|
|
new Thread( |
|
|
|
|
|
|
|
() -> { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
for (int i = 0; i < 1000; i++) { |
|
|
|
|
|
|
|
controller.removeNodes(Lists.newArrayList(enode1)); |
|
|
|
|
|
|
|
controller.addNodes(Lists.newArrayList(enode1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
exceptionOccurred.set(true); |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start both threads
|
|
|
|
|
|
|
|
isPermittedThread.start(); |
|
|
|
|
|
|
|
modifyAllowlistThread.start(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for both threads to complete
|
|
|
|
|
|
|
|
isPermittedThread.join(); |
|
|
|
|
|
|
|
modifyAllowlistThread.join(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assert no exceptions were thrown
|
|
|
|
|
|
|
|
assert (!exceptionOccurred.get()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void stateShouldRevertIfAllowlistPersistFails() |
|
|
|
public void stateShouldRevertIfAllowlistPersistFails() |
|
|
|
throws IOException, AllowlistFileSyncException { |
|
|
|
throws IOException, AllowlistFileSyncException { |
|
|
|