@Test public void testExpiringResource() throws Exception { Config config = ConfigFactory.empty(); SharedResourcesBrokerImpl<SimpleScopeType> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, SimpleScopeType.GLOBAL.defaultScopeInstance()); InvalidatableResourceFactory factory = new InvalidatableResourceFactory(); long value = topBroker.getSharedResource(factory, new EmptyKey()); Assert.assertEquals(topBroker.getSharedResource(factory, new EmptyKey()), new Long(value)); factory.getLastResourceEntry().setValid(false); Assert.assertNotEquals(topBroker.getSharedResource(factory, new EmptyKey()), value); value = topBroker.getSharedResource(factory, new EmptyKey()); Assert.assertEquals(topBroker.getSharedResource(factory, new EmptyKey()), new Long(value)); }
FileSystem defaultFS = FileSystem.get(new Configuration()); StreamThrottler<GobblinScopeTypes> throttler = this.taskBroker.getSharedResource(new StreamThrottler.Factory<GobblinScopeTypes>(), new EmptyKey()); ThrottledInputStream throttledInputStream = throttler.throttleInputStream().inputStream(inputStream) .sourceURI(copyableFile.getOrigin().getPath().makeQualified(defaultFS.getUri(), defaultFS.getWorkingDirectory()).toUri())
@Test public void testExplicitBinding() throws Exception { Config config = ConfigFactory.empty(); SharedResourcesBrokerImpl<SimpleScopeType> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, SimpleScopeType.GLOBAL.defaultScopeInstance()); SharedResourceFactory<Long, EmptyKey, SimpleScopeType> factory = new SharedResourceFactory<Long, EmptyKey, SimpleScopeType>() { @Override public String getName() { return "myTestFactory"; } @Override public SharedResourceFactoryResponse<Long> createResource(SharedResourcesBroker<SimpleScopeType> broker, ScopedConfigView<SimpleScopeType, EmptyKey> config) throws NotConfiguredException { throw new UnsupportedOperationException(); } @Override public SimpleScopeType getAutoScope(SharedResourcesBroker<SimpleScopeType> broker, ConfigView<SimpleScopeType, EmptyKey> config) { return broker.selfScope().getType(); } }; topBroker.bindSharedResourceAtScope(factory, new EmptyKey(), SimpleScopeType.GLOBAL, 10l); Assert.assertEquals(topBroker.getSharedResource(factory, new EmptyKey()), new Long(10)); }
FileSystem defaultFS = FileSystem.get(new Configuration()); StreamThrottler<GobblinScopeTypes> throttler = this.taskBroker.getSharedResource(new StreamThrottler.Factory<GobblinScopeTypes>(), new EmptyKey()); ThrottledInputStream throttledInputStream = throttler.throttleInputStream().inputStream(inputStream) .sourceURI(copyableFile.getOrigin().getPath().makeQualified(defaultFS.getUri(), defaultFS.getWorkingDirectory()).toUri())