|
15 | 15 | */ |
16 | 16 | package io.aeron.cluster.service; |
17 | 17 |
|
18 | | -import io.aeron.Aeron; |
19 | | -import io.aeron.ConcurrentPublication; |
20 | | -import io.aeron.Publication; |
21 | | -import io.aeron.Subscription; |
22 | | -import io.aeron.UnavailableCounterHandler; |
| 18 | +import io.aeron.*; |
23 | 19 | import io.aeron.cluster.client.AeronCluster; |
| 20 | +import io.aeron.cluster.codecs.CloseReason; |
24 | 21 | import io.aeron.driver.DutyCycleTracker; |
25 | 22 | import io.aeron.logbuffer.BufferClaim; |
26 | 23 | import io.aeron.test.CountersAnswer; |
27 | 24 | import io.aeron.test.Tests; |
28 | 25 | import org.agrona.DirectBuffer; |
| 26 | +import org.agrona.ErrorHandler; |
29 | 27 | import org.agrona.MutableDirectBuffer; |
30 | 28 | import org.agrona.concurrent.*; |
31 | 29 | import org.agrona.concurrent.errors.DistinctErrorLog; |
| 30 | +import org.agrona.concurrent.errors.ErrorLogReader; |
| 31 | +import org.agrona.concurrent.status.AtomicCounter; |
32 | 32 | import org.agrona.concurrent.status.CountersManager; |
33 | 33 | import org.junit.jupiter.api.Test; |
34 | 34 | import org.mockito.ArgumentCaptor; |
35 | 35 |
|
| 36 | +import java.nio.ByteBuffer; |
36 | 37 | import java.util.concurrent.TimeUnit; |
37 | 38 |
|
38 | 39 | import static io.aeron.Aeron.NULL_VALUE; |
39 | 40 | import static io.aeron.AeronCounters.CLUSTER_COMMIT_POSITION_TYPE_ID; |
40 | 41 | import static io.aeron.AeronCounters.CLUSTER_RECOVERY_STATE_TYPE_ID; |
41 | 42 | import static org.junit.jupiter.api.Assertions.assertEquals; |
42 | 43 | import static org.junit.jupiter.api.Assertions.assertThrowsExactly; |
| 44 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
43 | 45 | import static org.mockito.Mockito.*; |
44 | 46 |
|
45 | 47 | class ClusteredServiceAgentTest |
@@ -124,4 +126,28 @@ void shouldAbortClusteredServiceIfCommitPositionCounterIsClosed() |
124 | 126 | nanoClock.advance(TimeUnit.MILLISECONDS.toNanos(2)); |
125 | 127 | assertThrowsExactly(ClusterTerminationException.class, clusteredServiceAgent::doWork); |
126 | 128 | } |
| 129 | + |
| 130 | + @Test |
| 131 | + void shouldLogErrorInsteadOfThrowingIfSessionIsNotFoundOnClose() |
| 132 | + { |
| 133 | + final Aeron aeron = mock(Aeron.class); |
| 134 | + final DistinctErrorLog distinctErrorLog = new DistinctErrorLog( |
| 135 | + new UnsafeBuffer(ByteBuffer.allocateDirect(16384)), new SystemEpochClock()); |
| 136 | + final CountersManager countersManager = Tests.newCountersMananger(16 * 1024); |
| 137 | + final AtomicCounter errorCounter = countersManager.newCounter("test"); |
| 138 | + final long originalErrorCount = errorCounter.get(); |
| 139 | + |
| 140 | + final ErrorHandler errorHandler = CommonContext.setupErrorHandler(null, distinctErrorLog); |
| 141 | + final CountedErrorHandler countedErrorHandler = new CountedErrorHandler(errorHandler, errorCounter); |
| 142 | + final ClusteredServiceContainer.Context ctx = new ClusteredServiceContainer.Context() |
| 143 | + .aeron(aeron) |
| 144 | + .idleStrategySupplier(() -> YieldingIdleStrategy.INSTANCE) |
| 145 | + .countedErrorHandler(countedErrorHandler); |
| 146 | + final ClusteredServiceAgent clusteredServiceAgent = new ClusteredServiceAgent(ctx); |
| 147 | + |
| 148 | + clusteredServiceAgent.onSessionClose(99, 999, 9999, 99999, CloseReason.CLIENT_ACTION); |
| 149 | + |
| 150 | + assertEquals(originalErrorCount + 1, errorCounter.get()); |
| 151 | + assertTrue(ErrorLogReader.hasErrors(distinctErrorLog.buffer())); |
| 152 | + } |
127 | 153 | } |
0 commit comments