AssetBlobCleanupTaskManager extends LifecycleSupport implements EventAware, EventAware.Asynchronous { @Subscribe @AllowConcurrentEvents public void on(final RepositoryStartedEvent event) { String format = event.getRepository().getFormat().getValue(); Configuration repositoryConfiguration = event.getRepository().getConfiguration(); NestedAttributesMap storageAttributes = repositoryConfiguration.attributes(STORAGE); String contentStore = (String) storageAttributes.get(DATA_STORE_NAME, CONTENT_DATASTORE_NAME); if (activeFormatStores.put(format, contentStore) && isStarted()) { scheduleAssetBlobCleanupTask(format, contentStore); } } @Inject  AssetBlobCleanupTaskManager(final TaskScheduler taskScheduler); @Subscribe @AllowConcurrentEvents void on(final RepositoryStartedEvent event); @Subscribe @AllowConcurrentEvents void on(final TaskDeletedEvent event);  }
@Test public void testAutomaticScheduling() throws Exception { AssetBlobCleanupTaskManager taskManager = new AssetBlobCleanupTaskManager(taskScheduler); ArgumentCaptor<TaskConfiguration> configCaptor = forClass(TaskConfiguration.class); InOrder inOrder = inOrder(taskScheduler); taskManager.on(new RepositoryStartedEvent(rawRepository)); taskManager.on(new RepositoryStartedEvent(mavenReleaseRepository)); inOrder.verify(taskScheduler, never()).scheduleTask(any(), any()); taskManager.start(); inOrder.verify(taskScheduler).scheduleTask(configCaptor.capture(), any()); inOrder.verify(taskScheduler).scheduleTask(configCaptor.capture(), any()); assertThat(configCaptor.getAllValues().stream().map(TaskConfiguration::asMap).collect(toList()), containsInAnyOrder( allOf(hasEntry(FORMAT_FIELD_ID, "raw"), hasEntry(CONTENT_STORE_FIELD_ID, "rawContentStore")), allOf(hasEntry(FORMAT_FIELD_ID, "maven"), hasEntry(CONTENT_STORE_FIELD_ID, "mavenReleaseStore")))); taskManager.on(new RepositoryStartedEvent(mavenSnapshotRepository)); inOrder.verify(taskScheduler).scheduleTask(configCaptor.capture(), any()); assertThat(configCaptor.getValue().asMap(), allOf(hasEntry(FORMAT_FIELD_ID, "maven"), hasEntry(CONTENT_STORE_FIELD_ID, "mavenSnapshotStore"))); taskManager.on(new RepositoryStartedEvent(mavenReleaseRepository)); inOrder.verify(taskScheduler, never()).scheduleTask(any(), any()); taskManager.on(new TaskDeletedEvent(mavenReleaseTaskInfo)); taskManager.on(new RepositoryStartedEvent(mavenReleaseRepository)); inOrder.verify(taskScheduler).scheduleTask(configCaptor.capture(), any()); assertThat(configCaptor.getValue().asMap(), allOf(hasEntry(FORMAT_FIELD_ID, "maven"), hasEntry(CONTENT_STORE_FIELD_ID, "mavenReleaseStore"))); taskManager.stop(); inOrder.verifyNoMoreInteractions(); }