private void configureExtensionRule() { final ConventionMapping extensionMapping = conventionMappingOf(extension); extensionMapping.map("sourceSets", Callables.returning(new ArrayList())); extensionMapping.map("reportsDir", new Callable<File>() { @Override public File call() { return project.getExtensions().getByType(ReportingExtension.class).file(getReportName()); } }); withBasePlugin(new Action<Plugin>() { @Override public void execute(Plugin plugin) { extensionMapping.map("sourceSets", new Callable<SourceSetContainer>() { @Override public SourceSetContainer call() { return getJavaPluginConvention().getSourceSets(); } }); } }); }
/** * Configures the classpath for Jacoco tasks using the 'jacocoAnt' configuration. Uses the version information declared in 'toolVersion' of the Jacoco extension if no dependencies are explicitly * declared. * * @param extension the JacocoPluginExtension */ private void configureTaskClasspathDefaults(final JacocoPluginExtension extension) { final Configuration config = this.project.getConfigurations().getAt(ANT_CONFIGURATION_NAME); project.getTasks().withType(JacocoBase.class, new Action<JacocoBase>() { @Override public void execute(JacocoBase task) { ((IConventionAware) task).getConventionMapping().map("jacocoClasspath", Callables.returning(config)); } }); config.defaultDependencies(new Action<DependencySet>() { @Override public void execute(DependencySet dependencies) { dependencies.add(project.getDependencies().create("org.jacoco:org.jacoco.ant:" + extension.getToolVersion())); } }); }
private void configureJacocoReportDefaults(final JacocoPluginExtension extension, final JacocoReport reportTask) { reportTask.getReports().all(new Action<Report>() { @Override public void execute(final Report report) { ConventionMapping mapping = ((IConventionAware) report).getConventionMapping(); mapping.map("enabled", Callables.returning(report.getName().equals("html"))); if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) { mapping.map("destination", new Callable<File>() { @Override public File call() { return new File(extension.getReportsDir(), reportTask.getName() + "/" + report.getName()); } }); } else { mapping.map("destination", new Callable<File>() { @Override public File call() { return new File(extension.getReportsDir(), reportTask.getName() + "/" + reportTask.getName() + "." + report.getName()); } }); } } }); }
@Test public void testStaleFiresFutureListener() throws InterruptedException { Object obj = new Object(); final PluggableJob<Object> job = new PluggableJob<Object>("name", Callables.returning(obj), Predicates.alwaysTrue()); assertFalse(job.getFuture().isDone()); final boolean[] listenerRun = new boolean[] {false}; job.getFuture().addListener(new Runnable() { @Override public void run() { listenerRun[0] = true; assertTrue(job.getFuture().isCancelled()); } }, MoreExecutors.directExecutor()); assertFalse(listenerRun[0]); job.schedule(); job.join(); assertTrue(listenerRun[0]); assertEquals("Should be CANCEL", IStatus.CANCEL, job.getResult().getSeverity()); }
@Test public void testOnSuccess_normal() throws InterruptedException { Object obj = new Object(); PluggableJob<Object> job = new PluggableJob<Object>("name", Callables.returning(obj)); final boolean[] listenerRun = new boolean[] {false}; job.onSuccess(MoreExecutors.directExecutor(), new Runnable() { @Override public void run() { listenerRun[0] = true; } }); assertFalse(listenerRun[0]); job.schedule(); job.join(); assertTrue(listenerRun[0]); assertTrue(job.isComputationComplete()); }
@Test public void testOnSuccess_abandon() throws InterruptedException { Object obj = new Object(); PluggableJob<Object> job = new PluggableJob<Object>("name", Callables.returning(obj), Predicates.alwaysTrue()); final boolean[] listenerRun = new boolean[] {false}; job.onSuccess(MoreExecutors.directExecutor(), new Runnable() { @Override public void run() { listenerRun[0] = true; } }); assertFalse(listenerRun[0]); job.schedule(); // should be stale and cancelled job.join(); assertFalse("onSuccess should not have been called", listenerRun[0]); }
private void assertActionWithContentChangingInput(final boolean unconditionalExecution) throws Exception { // Assert that a simple, non-skyframe-aware action is executed twice // if its input's content changes between builds. assertActionExecutions( new ExecutionCountingActionFactory() { @Override public ExecutionCountingAction create( Artifact input, Artifact output, AtomicInteger executionCounter) { return unconditionalExecution ? new ExecutionCountingCacheBypassingAction(input, output, executionCounter) : new ExecutionCountingAction(input, output, executionCounter); } }, ChangeArtifact.CHANGE_MTIME_AND_CONTENT, Callables.<Void>returning(null), ExpectActionIs.REEXECUTED); }
private void assertActionWithMtimeChangingInput(final boolean unconditionalExecution) throws Exception { // Assert that a simple, non-skyframe-aware action is executed only once // if its input's mtime changes but its contents stay the same between builds. assertActionExecutions( new ExecutionCountingActionFactory() { @Override public ExecutionCountingAction create( Artifact input, Artifact output, AtomicInteger executionCounter) { return unconditionalExecution ? new ExecutionCountingCacheBypassingAction(input, output, executionCounter) : new ExecutionCountingAction(input, output, executionCounter); } }, ChangeArtifact.CHANGE_MTIME, Callables.<Void>returning(null), unconditionalExecution ? ExpectActionIs.REEXECUTED : ExpectActionIs.DIRTIED_BUT_VERIFIED_CLEAN); }
public void testActionWithNonChangingInput(final boolean unconditionalExecution) throws Exception { // Assert that a simple, non-skyframe-aware action is executed only once // if its input does not change at all between builds. assertActionExecutions( new ExecutionCountingActionFactory() { @Override public ExecutionCountingAction create( Artifact input, Artifact output, AtomicInteger executionCounter) { return unconditionalExecution ? new ExecutionCountingCacheBypassingAction(input, output, executionCounter) : new ExecutionCountingAction(input, output, executionCounter); } }, ChangeArtifact.DONT_CHANGE, Callables.<Void>returning(null), ExpectActionIs.NOT_DIRTIED); }
private void configureReportsConventionMapping(Pmd task, final String baseName) { task.getReports().all(new Action<SingleFileReport>() { @Override public void execute(final SingleFileReport report) { ConventionMapping reportMapping = AbstractCodeQualityPlugin.conventionMappingOf(report); reportMapping.map("enabled", Callables.returning(true)); reportMapping.map("destination", new Callable<File>() { @Override public File call() { return new File(extension.getReportsDir(), baseName + "." + report.getName()); } }); } }); }
private void configureTaskConventionMapping(Configuration configuration, Checkstyle task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("checkstyleClasspath", Callables.returning(configuration)); taskMapping.map("config", new Callable<TextResource>() { @Override public TextResource call() { return extension.getConfig(); } }); taskMapping.map("configProperties", new Callable<Map<String, Object>>() { @Override public Map<String, Object> call() { return extension.getConfigProperties(); } }); taskMapping.map("ignoreFailures", new Callable<Boolean>() { @Override public Boolean call() { return extension.isIgnoreFailures(); } }); taskMapping.map("showViolations", new Callable<Boolean>() { @Override public Boolean call() { return extension.isShowViolations(); } }); }
private void configureReportsConventionMapping(Checkstyle task, final String baseName) { task.getReports().all(new Action<SingleFileReport>() { @Override public void execute(final SingleFileReport report) { ConventionMapping reportMapping = conventionMappingOf(report); reportMapping.map("enabled", Callables.returning(true)); reportMapping.map("destination", new Callable<File>() { @Override public File call() { return new File(extension.getReportsDir(), baseName + "." + report.getName()); } }); } }); }
private void configureTaskConventionMapping(Configuration configuration, CodeNarc task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("codenarcClasspath", Callables.returning(configuration)); taskMapping.map("config", new Callable<TextResource>() { @Override public TextResource call() { return extension.getConfig(); } }); taskMapping.map("maxPriority1Violations", new Callable<Integer>() { @Override public Integer call() { return extension.getMaxPriority1Violations(); } }); taskMapping.map("maxPriority2Violations", new Callable<Integer>() { @Override public Integer call() { return extension.getMaxPriority2Violations(); } }); taskMapping.map("maxPriority3Violations", new Callable<Integer>() { @Override public Integer call() { return extension.getMaxPriority3Violations(); } }); taskMapping.map("ignoreFailures", new Callable<Boolean>() { @Override public Boolean call() { return extension.isIgnoreFailures(); } }); }
/** * Configures the agent dependencies using the 'jacocoAnt' configuration. Uses the version declared in 'toolVersion' of the Jacoco extension if no dependencies are explicitly declared. * * @param extension the extension that has the tool version to use */ private void configureAgentDependencies(JacocoAgentJar jacocoAgentJar, final JacocoPluginExtension extension) { Configuration config = project.getConfigurations().getAt(AGENT_CONFIGURATION_NAME); ((IConventionAware) jacocoAgentJar).getConventionMapping().map("agentConf", Callables.returning(config)); config.defaultDependencies(new Action<DependencySet>() { @Override public void execute(DependencySet dependencies) { dependencies.add(project.getDependencies().create("org.jacoco:org.jacoco.agent:" + extension.getToolVersion())); } }); }
private void configureTaskConventionMapping(Configuration configuration, Pmd task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("pmdClasspath", Callables.returning(configuration)); taskMapping.map("ruleSets", () -> extension.getRuleSets()); taskMapping.map("ruleSetConfig", () -> extension.getRuleSetConfig()); taskMapping.map("ruleSetFiles", () -> extension.getRuleSetFiles()); taskMapping.map("ignoreFailures", () -> extension.isIgnoreFailures()); taskMapping.map("rulePriority", () -> extension.getRulePriority()); taskMapping.map("consoleOutput", () -> extension.isConsoleOutput()); taskMapping.map("targetJdk", () -> extension.getTargetJdk()); }
private void configureReportsConventionMapping(Pmd task, final String baseName) { task.getReports().all(report -> { ConventionMapping reportMapping = conventionMappingOf(report); reportMapping.map("enabled", Callables.returning(true)); reportMapping.map("destination", () -> new File(extension.getReportsDir(), baseName + "." + report.getName())); }); }
private void configureExtensionRule() { final ConventionMapping extensionMapping = conventionMappingOf(extension); String sourceSets = getExtensionElementsName(); Callable<Collection<?>> ssCallable = getExtensionElementsCallable(); extensionMapping.map(sourceSets, Callables.returning(new ArrayList())); extensionMapping.map("reportsDir", () -> project.getExtensions().getByType(ReportingExtension.class).file(getReportName())); withBasePlugin(plugin -> extensionMapping.map(sourceSets, ssCallable)); }
private void configureTaskConventionMapping(Configuration configuration, FindBugs task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("findbugsClasspath", Callables.returning(configuration)); taskMapping.map("ignoreFailures", () -> extension.isIgnoreFailures()); taskMapping.map("effort", () -> extension.getEffort()); taskMapping.map("reportLevel", () -> extension.getReportLevel()); taskMapping.map("visitors", () -> extension.getVisitors()); taskMapping.map("omitVisitors", () -> extension.getOmitVisitors()); taskMapping.map("excludeFilterConfig", () -> extension.getExcludeFilterConfig()); taskMapping.map("includeFilterConfig", () -> extension.getIncludeFilterConfig()); taskMapping.map("excludeBugsFilterConfig", () -> extension.getExcludeBugsFilterConfig()); taskMapping.map("extraArgs", () -> extension.getExtraArgs()); }
private void configureTaskConventionMapping(Configuration configuration, Checkstyle task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("checkstyleClasspath", Callables.returning(configuration)); taskMapping.map("config", () -> extension.getConfig()); taskMapping.map("configProperties", () -> extension.getConfigProperties()); taskMapping.map("ignoreFailures", () -> extension.isIgnoreFailures()); taskMapping.map("showViolations", () -> extension.isShowViolations()); }
private void configureReportsConventionMapping(Checkstyle task, final String baseName) { task.getReports().all(report -> { ConventionMapping reportMapping = conventionMappingOf(report); reportMapping.map("enabled", Callables.returning(true)); reportMapping.map("destination", () -> new File(extension.getReportsDir(), baseName + "." + report.getName())); }); }
@Test public void testConstructor_nullStalenessCheck() { try { new PluggableJob<Void>("name", Callables.returning((Void) null), null); fail("Expected NPE"); } catch (NullPointerException ex) { } }
@Test public void testScheduled() throws InterruptedException, ExecutionException { Object obj = new Object(); PluggableJob<Object> job = new PluggableJob<Object>("name", Callables.returning(obj)); assertFalse(job.getFuture().isDone()); assertFalse(job.getFuture().isCancelled()); job.schedule(); job.join(); assertTrue(job.getFuture().isDone()); assertFalse(job.getFuture().isCancelled()); assertSame(obj, job.getFuture().get()); assertEquals("Should be OK", IStatus.OK, job.getResult().getSeverity()); }
@Test public void testStaleCancelsFuture() throws InterruptedException { Object obj = new Object(); PluggableJob<Object> job = new PluggableJob<Object>("name", Callables.returning(obj), Predicates.alwaysTrue()); job.schedule(); job.join(); assertEquals("Should be CANCEL", IStatus.CANCEL, job.getResult().getSeverity()); assertTrue(job.getFuture().isCancelled()); }
@Test public void testCompleteness_normal() throws InterruptedException { Object obj = new Object(); PluggableJob<Object> job = new PluggableJob<Object>("name", Callables.returning(obj)); assertFalse(job.isComputationComplete()); job.schedule(); job.join(); assertTrue(job.isComputationComplete()); assertFalse(job.getComputationError().isPresent()); assertTrue(job.getComputationResult().isPresent()); assertEquals(obj, job.getComputationResult().get()); assertEquals(obj, job.getComputation().get()); }
@Test public void testIsCurrent_abandon() throws InterruptedException { Object obj = new Object(); PluggableJob<Object> job = new PluggableJob<Object>("name", Callables.returning(obj)); assertTrue(job.isCurrent()); job.schedule(); // should be stale and cancelled job.join(); assertTrue(job.isCurrent()); job.abandon(); assertFalse("Abandoned jobs should not be current", job.isCurrent()); }
/** * Test defaults (retry once only) on success. */ @Test public void testWithDefaultsOnSuccess() throws Exception { Callable<String> task = Callables.returning("hello world"); Retryable<String> retryable = new Retryable<>(task); String result = retryable.call(); assertThat(result, is("hello world")); assertThat(retryable.getAttempts(), is(1)); }
@Test public void testGetDocContentListEmptyDefaultView() throws Exception { SiteDataSoap siteData = MockSiteData.blank() .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_URLSEG_EXCHANGE) .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_L_CONTENT_EXCHANGE .replaceInContent("DefaultViewUrl=\"/sites/SiteCollection/Lists/" + "Custom List/AllItems.aspx\"", "DefaultViewUrl=\"/\"")) .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_F_CONTENT_EXCHANGE) .register(SITES_SITECOLLECTION_S_CONTENT_EXCHANGE) .register(new URLSegmentsExchange( "http://localhost:1/sites/SiteCollection/Lists/Custom List", true, null, null, "{6F33949A-B3FF-4B0C-BA99-93CB518AC2C0}", null)); adaptor = new SharePointAdaptor(initableSoapFactory, new UnsupportedHttpClient(), executorFactory, new MockAuthenticationClientFactoryForms(), new UnsupportedActiveDirectoryClientFactory()); RecordingDocIdPusher pusher = new RecordingDocIdPusher(); adaptor.init(new MockAdaptorContext(config, pusher)); DocRequest request = new DocRequest( new DocId("http://localhost:1/sites/SiteCollection/Lists/Custom List")); RecordingResponse response = new RecordingResponse(); adaptor.new SiteAdaptor("http://localhost:1/sites/SiteCollection", "http://localhost:1/sites/SiteCollection", siteData, new UnsupportedUserGroupSoap(), new UnsupportedPeopleSoap(), Callables.returning(SITES_SITECOLLECTION_MEMBER_MAPPING), new UnsupportedCallable<MemberIdMapping>()) .getDocContent(request, response); // Verify display URL for List document assertEquals(URI.create("http://localhost:1/sites/SiteCollection/Lists/" + "Custom%20List"), response.getDisplayUrl()); }
@Test public void testGetDocContentFolderEmptyDefaultView() throws Exception { SiteDataSoap siteData = MockSiteData.blank() .register(SITES_SITECOLLECTION_S_CONTENT_EXCHANGE) .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_1_URLSEG_EXCHANGE) .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_L_CONTENT_EXCHANGE .replaceInContent("DefaultViewUrl=\"/sites/SiteCollection/Lists/" + "Custom List/AllItems.aspx\"", "DefaultViewUrl=\"/\"")) .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_1_LI_CONTENT_EXCHANGE) .register(SITES_SITECOLLECTION_LISTS_CUSTOMLIST_1_F_CONTENT_EXCHANGE); adaptor = new SharePointAdaptor(initableSoapFactory, new UnsupportedHttpClient(), executorFactory, new MockAuthenticationClientFactoryForms(), new UnsupportedActiveDirectoryClientFactory()); adaptor.init(new MockAdaptorContext(config, pusher)); DocRequest request = new DocRequest( new DocId("http://localhost:1/sites/SiteCollection/Lists/Custom List/" + "Test Folder")); RecordingResponse response = new RecordingResponse(); adaptor.new SiteAdaptor("http://localhost:1/sites/SiteCollection", "http://localhost:1/sites/SiteCollection", siteData, new UnsupportedUserGroupSoap(), new UnsupportedPeopleSoap(), Callables.returning(SITES_SITECOLLECTION_MEMBER_MAPPING), new UnsupportedCallable<MemberIdMapping>()) .getDocContent(request, response); assertEquals(URI.create("http://localhost:1/sites/SiteCollection/Lists/" + "Custom%20List?RootFolder=/sites/SiteCollection/" + "Lists/Custom%20List/Test%20Folder"),response.getDisplayUrl()); }
private void updateController(final String appName, final RunId runId, final AtomicBoolean cancelled) { String instancePath = String.format("/%s/instances/%s", appName, runId.getId()); // Fetch the content node. Futures.addCallback(zkClientService.getData(instancePath), new FutureCallback<NodeData>() { @Override public void onSuccess(NodeData result) { if (cancelled.get()) { return; } ApplicationId appId = getApplicationId(result); if (appId == null) { return; } synchronized (YarnTwillRunnerService.this) { if (!controllers.contains(appName, runId)) { ZKClient zkClient = ZKClients.namespace(zkClientService, "/" + appName); YarnTwillController controller = listenController( new YarnTwillController(appName, runId, zkClient, Callables.returning(yarnAppClient.createProcessController(appId)))); controllers.put(appName, runId, controller); controller.start(); } } } @Override public void onFailure(Throwable t) { LOG.warn("Failed in fetching application instance node.", t); } }, Threads.SAME_THREAD_EXECUTOR); }
/** * Put a dummy task into the queue and wait for it to be run. Because it's single threaded, this means all * tasks submitted before this point are now completed. Usually you won't want to use this method - it's a * convenience primarily used in unit testing. If you want to wait for an event to be called the right thing * to do is usually to create a {@link com.google.common.util.concurrent.SettableFuture} and then call set * on it. You can then either block on that future, compose it, add listeners to it and so on. */ public static void waitForUserCode() { // If this assert fires it means you have a bug in your code - you can't call this method inside your own // event handlers because it would never return. If you aren't calling this method explicitly, then that // means there's a bug in digitalcoinj. if (vUserThread != null) { checkState(vUserThread.get() != null && vUserThread.get() != Thread.currentThread(), "waitForUserCode() run on user code thread would deadlock."); } Futures.getUnchecked(SINGLE_THREADED_EXECUTOR.submit(Callables.returning(null))); }
private void configureJGivenReportDefaults( Project project ) { project.getTasks().withType( JGivenReportTask.class, new Action<JGivenReportTask>() { @Override public void execute( JGivenReportTask reportTask ) { reportTask.getReports().all( new Action<Report>() { @Override public void execute( final Report report ) { ConventionMapping mapping = ( (IConventionAware) report ).getConventionMapping(); mapping.map( "enabled", Callables.returning( report.getName().equals( JGivenHtmlReportImpl.NAME ) ) ); } } ); } } ); }
/** * Put a dummy task into the queue and wait for it to be run. Because it's single threaded, this means all * tasks submitted before this point are now completed. Usually you won't want to use this method - it's a * convenience primarily used in unit testing. If you want to wait for an event to be called the right thing * to do is usually to create a {@link com.google.common.util.concurrent.SettableFuture} and then call set * on it. You can then either block on that future, compose it, add listeners to it and so on. */ public static void waitForUserCode() { // If this assert fires it means you have a bug in your code - you can't call this method inside your own // event handlers because it would never return. If you aren't calling this method explicitly, then that // means there's a bug in bitcoinj. if (vUserThread != null) { checkState(vUserThread.get() != null && vUserThread.get() != Thread.currentThread(), "waitForUserCode() run on user code thread would deadlock."); } Futures.getUnchecked(SINGLE_THREADED_EXECUTOR.submit(Callables.returning(null))); }
private void addTaskToProject(Project project, Class<? extends AbstractJavaccTask> type, String name, String description, String group, Configuration configuration) { Map<String, Object> options = new HashMap<String, Object>(2); options.put(Task.TASK_TYPE, type); options.put(Task.TASK_DESCRIPTION, description); options.put(Task.TASK_GROUP, group); AbstractJavaccTask task = (AbstractJavaccTask) project.task(options, name); task.getConventionMapping().map("classpath", Callables.returning(configuration)); }
private void configureTaskConventionMapping(Configuration configuration, JDepend task) { conventionMappingOf(task).map("jdependClasspath", Callables.returning(configuration)); }
private void configureTaskConventionMapping(Configuration configuration, Pmd task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("pmdClasspath", Callables.returning(configuration)); taskMapping.map("ruleSets", new Callable<List<String>>() { @Override public List<String> call() { return extension.getRuleSets(); } }); taskMapping.map("ruleSetConfig", new Callable<TextResource>() { @Override public TextResource call() { return extension.getRuleSetConfig(); } }); taskMapping.map("ruleSetFiles", new Callable<FileCollection>() { @Override public FileCollection call() { return extension.getRuleSetFiles(); } }); taskMapping.map("ignoreFailures", new Callable<Boolean>() { @Override public Boolean call() { return extension.isIgnoreFailures(); } }); taskMapping.map("rulePriority", new Callable<Integer>() { @Override public Integer call() { return extension.getRulePriority(); } }); taskMapping.map("consoleOutput", new Callable<Boolean>() { @Override public Boolean call() { return extension.isConsoleOutput(); } }); taskMapping.map("targetJdk", new Callable<TargetJdk>() { @Override public TargetJdk call() { return extension.getTargetJdk(); } }); }
private void configureTaskConventionMapping(Configuration configuration, FindBugs task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("findbugsClasspath", Callables.returning(configuration)); taskMapping.map("ignoreFailures", new Callable<Boolean>() { @Override public Boolean call() { return extension.isIgnoreFailures(); } }); taskMapping.map("effort", new Callable<String>() { @Override public String call() { return extension.getEffort(); } }); taskMapping.map("reportLevel", new Callable<String>() { @Override public String call() { return extension.getReportLevel(); } }); taskMapping.map("visitors", new Callable<Collection<String>>() { @Override public Collection<String> call() { return extension.getVisitors(); } }); taskMapping.map("omitVisitors", new Callable<Collection<String>>() { @Override public Collection<String> call() { return extension.getOmitVisitors(); } }); taskMapping.map("excludeFilterConfig", new Callable<TextResource>() { @Override public TextResource call() { return extension.getExcludeFilterConfig(); } }); taskMapping.map("includeFilterConfig", new Callable<TextResource>() { @Override public TextResource call() { return extension.getIncludeFilterConfig(); } }); taskMapping.map("excludeBugsFilterConfig", new Callable<TextResource>() { @Override public TextResource call() { return extension.getExcludeBugsFilterConfig(); } }); taskMapping.map("extraArgs", new Callable<Collection<String>>() { @Override public Collection<String> call() { return extension.getExtraArgs(); } }); }
public void testLoad() throws ExecutionException { LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .recordStats() .build(identityLoader()); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); Object key = new Object(); assertSame(key, cache.get(key)); stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(1, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); key = new Object(); assertSame(key, cache.getUnchecked(key)); stats = cache.stats(); assertEquals(2, stats.missCount()); assertEquals(2, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); key = new Object(); cache.refresh(key); checkNothingLogged(); stats = cache.stats(); assertEquals(2, stats.missCount()); assertEquals(3, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); assertSame(key, cache.get(key)); stats = cache.stats(); assertEquals(2, stats.missCount()); assertEquals(3, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(1, stats.hitCount()); Object value = new Object(); // callable is not called assertSame(key, cache.get(key, throwing(new Exception()))); stats = cache.stats(); assertEquals(2, stats.missCount()); assertEquals(3, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(2, stats.hitCount()); key = new Object(); assertSame(value, cache.get(key, Callables.returning(value))); stats = cache.stats(); assertEquals(3, stats.missCount()); assertEquals(4, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(2, stats.hitCount()); }
public void testExpirationOrder_write() throws ExecutionException { // test lru within a single segment FakeTicker ticker = new FakeTicker(); IdentityLoader<Integer> loader = identityLoader(); LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder() .concurrencyLevel(1) .expireAfterWrite(11, MILLISECONDS) .ticker(ticker) .build(loader); for (int i = 0; i < 10; i++) { cache.getUnchecked(i); ticker.advance(1, MILLISECONDS); } Set<Integer> keySet = cache.asMap().keySet(); assertThat(keySet).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); // 0 expires ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9); // get doesn't stop 1 from expiring getAll(cache, asList(0, 1, 2)); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(2, 3, 4, 5, 6, 7, 8, 9, 0); // get(K, Callable) doesn't stop 2 from expiring cache.get(2, Callables.returning(-2)); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0); // asMap.put saves 3 cache.asMap().put(3, -3); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(4, 5, 6, 7, 8, 9, 0, 3); // asMap.replace saves 4 cache.asMap().replace(4, -4); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(5, 6, 7, 8, 9, 0, 3, 4); // 5 expires ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(6, 7, 8, 9, 0, 3, 4); }