|
28 | 28 | import java.util.List; |
29 | 29 | import java.util.Set; |
30 | 30 | import java.util.concurrent.atomic.AtomicLong; |
| 31 | +import java.util.concurrent.atomic.AtomicReference; |
31 | 32 |
|
32 | 33 | import org.junit.jupiter.api.Test; |
33 | 34 |
|
@@ -117,6 +118,42 @@ void shouldDisableHeavyOperatorExecutionOnlyWhileCritical() throws Exception { |
117 | 118 | assertTrue(readHeavyOperatorExecutionEnabled()); |
118 | 119 | } |
119 | 120 |
|
| 121 | + @Test |
| 122 | + void shouldClearCriticalKillSwitchImmediatelyWhenBreakerIsDisabled() throws Exception { |
| 123 | + Fixture fixture = new Fixture(); |
| 124 | + AtomicReference<QueryCircuitBreaker.Configuration> configuration = new AtomicReference<>( |
| 125 | + configuration(true, 100, 200, 300, 400, 300, 200, 25, 10, 1000, 7)); |
| 126 | + QueryCircuitBreaker breaker = new QueryCircuitBreaker(fixture.monitor, configuration::get, fixture.clock::get, |
| 127 | + fixture.sleeps::add, () -> { |
| 128 | + }, 1000, 1, false); |
| 129 | + |
| 130 | + try { |
| 131 | + fixture.freeMemoryMb.set(150); |
| 132 | + assertEquals("CRITICAL", breaker.snapshotStatus().getState()); |
| 133 | + assertFalse(readHeavyOperatorExecutionEnabled()); |
| 134 | + |
| 135 | + configuration.set(configuration(false, 100, 200, 300, 400, 300, 200, 25, 10, 1000, 7)); |
| 136 | + |
| 137 | + assertEquals("NORMAL", breaker.snapshotStatus().getState()); |
| 138 | + assertTrue(readHeavyOperatorExecutionEnabled()); |
| 139 | + } finally { |
| 140 | + QueryExecutionContext.setHeavyOperatorExecutionEnabled(true); |
| 141 | + QueryExecutionContext.setIgnoreCheckpointStride(false); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + void shouldNotRunGcFromStatusSnapshotTransition() { |
| 147 | + Fixture fixture = new Fixture(); |
| 148 | + QueryCircuitBreaker breaker = fixture.breaker(configuration(true, 100, 200, 300, 400, 300, 200, 25, 10, 1000, |
| 149 | + 7), 1000, () -> fixture.gcInvocations.add(fixture.clock.get())); |
| 150 | + |
| 151 | + fixture.freeMemoryMb.set(250); |
| 152 | + |
| 153 | + assertEquals("HIGH", breaker.snapshotStatus().getState()); |
| 154 | + assertEquals(List.of(), fixture.gcInvocations); |
| 155 | + } |
| 156 | + |
120 | 157 | @Test |
121 | 158 | void shouldNotLeaveCurrentThreadInterruptedWhenSelfCancelling() { |
122 | 159 | QueryCircuitBreakerHandle handle = new QueryCircuitBreakerHandle("self-cancel", |
|
0 commit comments