RestRequestCancellationRegistry { public IRegistrationHandle register(String requestId, Object userId, RunMonitor runMonitor) { assertNotNull(requestId, "requestId is required"); assertNotNull(runMonitor, "runMonitor is required"); final ConcurrentMap<String, RequestCancellationInfo> cancellationInfos = getRequestCancellationInfos(); if (cancellationInfos.putIfAbsent(requestId, new RequestCancellationInfo(runMonitor, userId)) != null) { LOG.warn("Duplicate request id. Ignoring this request: [requestId:{}]", requestId); return null; } return () -> cancellationInfos.remove(requestId); }  IRegistrationHandle register(String requestId, Object userId, RunMonitor runMonitor); boolean cancel(String requestId, Object userId);  }
@Test public void testRegisterInvalid() { assertThrows(AssertionException.class, () -> m_registry.register(null, null, null)); assertThrows(AssertionException.class, () -> m_registry.register("1", null, null)); assertThrows(AssertionException.class, () -> m_registry.register(null, "1", null)); assertThrows(AssertionException.class, () -> m_registry.register(null, null, m_runMonitor)); m_registry.register("1", null, m_runMonitor); }
@Test public void testRegisterSameRequestIdMultipleTimes() { assertFalse(m_runMonitor.isCancelled()); assertNotNull(m_registry.register("1", null, m_runMonitor)); assertNull(m_registry.register("1", "alice", m_runMonitor)); }