@Test public void testUnlock() { LockManagerImpl lockManager = new LockManagerImpl(); ClientDescriptor clientDescriptor = new TestClientDescriptor(); assertThat(lockManager.lock(1L, clientDescriptor), is(true)); lockManager.unlock(1L); assertThat(lockManager.lock(1L, clientDescriptor), is(true)); }
@Test public void testCreateLockStateAfterFailover() { LockManagerImpl lockManager = new LockManagerImpl(); ClientDescriptor clientDescriptor = new TestClientDescriptor(); Set<Long> locks = new HashSet<>(); locks.add(1L); locks.add(100L); locks.add(1000L); lockManager.createLockStateAfterFailover(clientDescriptor, locks); ClientDescriptor clientDescriptor1 = new TestClientDescriptor(); assertThat(lockManager.lock(100L, clientDescriptor1), is(false)); assertThat(lockManager.lock(1000L, clientDescriptor1), is(false)); assertThat(lockManager.lock(1L, clientDescriptor1), is(false)); }
@Test public void testLock() { LockManagerImpl lockManager = new LockManagerImpl(); ClientDescriptor clientDescriptor = new TestClientDescriptor(); assertThat(lockManager.lock(1L, clientDescriptor), is(true)); assertThat(lockManager.lock(1L, clientDescriptor), is(false)); assertThat(lockManager.lock(2L, clientDescriptor), is(true)); }
@Test @SuppressWarnings("unchecked") public void testSweepLocksForClient() { LockManagerImpl lockManager = new LockManagerImpl(); ClientDescriptor clientDescriptor1 = new TestClientDescriptor(); ClientDescriptor clientDescriptor2 = new TestClientDescriptor(); assertThat(lockManager.lock(1L, clientDescriptor1), is(true)); assertThat(lockManager.lock(2L, clientDescriptor1), is(true)); assertThat(lockManager.lock(3L, clientDescriptor1), is(true)); assertThat(lockManager.lock(4L, clientDescriptor1), is(true)); assertThat(lockManager.lock(5L, clientDescriptor2), is(true)); assertThat(lockManager.lock(6L, clientDescriptor2), is(true)); AtomicInteger counter = new AtomicInteger(); Consumer<List<Long>> consumer = mock(Consumer.class); ArgumentCaptor<List<Long>> argumentCaptor = ArgumentCaptor.forClass(List.class); doAnswer(invocation -> counter.incrementAndGet()).when(consumer).accept(argumentCaptor.capture()); lockManager.sweepLocksForClient(clientDescriptor2, consumer); assertThat(counter.get(), is(1)); assertThat(argumentCaptor.getValue().size(), is(2)); assertThat(argumentCaptor.getValue(), containsInAnyOrder(5L, 6L)); assertThat(lockManager.lock(5L, clientDescriptor2), is(true)); assertThat(lockManager.lock(6L, clientDescriptor2), is(true)); assertThat(lockManager.lock(1L, clientDescriptor1), is(false)); assertThat(lockManager.lock(2L, clientDescriptor1), is(false)); assertThat(lockManager.lock(3L, clientDescriptor1), is(false)); assertThat(lockManager.lock(4L, clientDescriptor1), is(false)); }
@SuppressWarnings("unchecked") public ClusterTierActiveEntity(ServiceRegistry registry, ClusterTierEntityConfiguration entityConfiguration, KeySegmentMapper defaultMapper) throws ConfigurationException { if (entityConfiguration == null) { throw new ConfigurationException("ClusteredStoreEntityConfiguration cannot be null"); } storeIdentifier = entityConfiguration.getStoreIdentifier(); configuration = entityConfiguration.getConfiguration(); managerIdentifier = entityConfiguration.getManagerIdentifier(); try { clientCommunicator = registry.getService(new CommunicatorServiceConfiguration()); stateService = registry.getService(new EhcacheStoreStateServiceConfig(entityConfiguration.getManagerIdentifier(), defaultMapper)); entityMessenger = registry.getService(new BasicServiceConfiguration<>(IEntityMessenger.class)); messageHandler = registry.getService(new OOOMessageHandlerConfiguration<>(managerIdentifier + "###" + storeIdentifier, ClusterTierActiveEntity::isTrackedMessage, defaultMapper.getSegments() + 1, new MessageToTrackerSegmentFunction(clusterTierConcurrency(defaultMapper)))); } catch (ServiceException e) { throw new ConfigurationException("Unable to retrieve service: " + e.getMessage()); } if (entityMessenger == null) { throw new AssertionError("Server failed to retrieve IEntityMessenger service."); } management = new ClusterTierManagement(registry, stateService, true, storeIdentifier, entityConfiguration.getManagerIdentifier()); chainCompactionLimit = Integer.getInteger(CHAIN_COMPACTION_THRESHOLD_PROP, DEFAULT_CHAIN_COMPACTION_THRESHOLD); if (configuration.isLoaderWriterConfigured()) { lockManager = new LockManagerImpl(); } else { lockManager = new NoopLockManager(); } }