|
20 | 20 | import static org.assertj.core.api.Assertions.assertThat; |
21 | 21 | import static org.mockito.ArgumentMatchers.any; |
22 | 22 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 23 | +import static org.mockito.Mockito.doAnswer; |
23 | 24 | import static org.mockito.Mockito.doNothing; |
| 25 | +import static org.mockito.Mockito.doReturn; |
24 | 26 | import static org.mockito.Mockito.mock; |
25 | 27 | import static org.mockito.Mockito.never; |
26 | 28 | import static org.mockito.Mockito.spy; |
|
30 | 32 |
|
31 | 33 | import java.net.InetAddress; |
32 | 34 | import java.net.Socket; |
| 35 | +import java.util.concurrent.ExecutorService; |
| 36 | +import java.util.concurrent.atomic.AtomicBoolean; |
33 | 37 |
|
34 | 38 | import org.apache.shiro.subject.Subject; |
35 | 39 | import org.junit.Before; |
| 40 | +import org.junit.Rule; |
36 | 41 | import org.junit.Test; |
| 42 | +import org.mockito.stubbing.Answer; |
37 | 43 |
|
38 | 44 | import org.apache.geode.StatisticsFactory; |
| 45 | +import org.apache.geode.distributed.internal.DistributionManager; |
| 46 | +import org.apache.geode.distributed.internal.OperationExecutors; |
39 | 47 | import org.apache.geode.internal.cache.Conflatable; |
40 | 48 | import org.apache.geode.internal.cache.InternalCache; |
41 | 49 | import org.apache.geode.internal.cache.tier.sockets.CacheClientProxy.CacheClientProxyStatsFactory; |
42 | 50 | import org.apache.geode.internal.cache.tier.sockets.CacheClientProxy.MessageDispatcherFactory; |
43 | 51 | import org.apache.geode.internal.security.SecurityService; |
44 | 52 | import org.apache.geode.internal.serialization.KnownVersion; |
45 | 53 | import org.apache.geode.internal.statistics.StatisticsClock; |
| 54 | +import org.apache.geode.test.junit.rules.ExecutorServiceRule; |
46 | 55 |
|
47 | 56 | public class CacheClientProxyTest { |
48 | 57 | private CacheClientProxy proxyWithSingleUser; |
@@ -71,6 +80,7 @@ public void before() throws Exception { |
71 | 80 | when(socket.getInetAddress()).thenReturn(inetAddress); |
72 | 81 | when(notifier.getAcceptorStats()).thenReturn(stats); |
73 | 82 | id = mock(ClientProxyMembershipID.class); |
| 83 | + when(id.getDurableId()).thenReturn("proxy_id"); |
74 | 84 | version = KnownVersion.TEST_VERSION; |
75 | 85 | securityService = mock(SecurityService.class); |
76 | 86 | subject = mock(Subject.class); |
@@ -175,4 +185,37 @@ public void close_multiUser_calls_ClientUserAuthsCleanUp() { |
175 | 185 | verify(subject, never()).logout(); |
176 | 186 | verify(clientUserAuths, times(1)).cleanup(anyBoolean()); |
177 | 187 | } |
| 188 | + |
| 189 | + @Rule |
| 190 | + public ExecutorServiceRule executorService = new ExecutorServiceRule(); |
| 191 | + |
| 192 | + @Test |
| 193 | + public void notifyReAuthenticationIsNotBlocked() { |
| 194 | + CacheClientProxy spy = spy(proxyWithSingleUser); |
| 195 | + MessageDispatcher dispatcher = mock(MessageDispatcher.class); |
| 196 | + doReturn(dispatcher).when(spy).createMessageDispatcher(any()); |
| 197 | + spy.initializeMessageDispatcher(); |
| 198 | + DistributionManager manager = mock(DistributionManager.class); |
| 199 | + OperationExecutors executors = mock(OperationExecutors.class); |
| 200 | + ExecutorService executor = executorService.getExecutorService(); |
| 201 | + when(cache.getDistributionManager()).thenReturn(manager); |
| 202 | + when(manager.getExecutors()).thenReturn(executors); |
| 203 | + when(executors.getWaitingThreadPool()).thenReturn(executor); |
| 204 | + |
| 205 | + AtomicBoolean updated = new AtomicBoolean(false); |
| 206 | + |
| 207 | + // simulating a blocked message dispatcher when notify reauth |
| 208 | + doAnswer((Answer<Void>) invocation -> { |
| 209 | + while (!updated.get()) { |
| 210 | + Thread.sleep(200); |
| 211 | + } |
| 212 | + return null; |
| 213 | + }).when(dispatcher).notifyReAuthentication(); |
| 214 | + |
| 215 | + // proxy.notifyReauthentication won't be blocked |
| 216 | + spy.notifyReAuthentication(); |
| 217 | + assertThat(updated.get()).isFalse(); |
| 218 | + } |
| 219 | + |
| 220 | + |
178 | 221 | } |
0 commit comments