Java Code Examples for com.typesafe.config.ConfigFactory#empty()
The following examples show how to use
com.typesafe.config.ConfigFactory#empty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValidatorTest.java From kite with Apache License 2.0 | 6 votes |
@Test public void testValidatorEnums() { Config empty = ConfigFactory.empty(); NumRequiredMatches param; param = null; param = new Validator<NumRequiredMatches>().validateEnum(empty, "all", NumRequiredMatches.class); assertEquals(param, NumRequiredMatches.all); param = null; param = new Validator<NumRequiredMatches>().validateEnum(empty, "all", NumRequiredMatches.class, NumRequiredMatches.all); assertEquals(param, NumRequiredMatches.all); param = null; try { param = new Validator<NumRequiredMatches>().validateEnum(empty, "all", NumRequiredMatches.class, NumRequiredMatches.atLeastOnce, NumRequiredMatches.once); fail(); } catch (MorphlineCompilationException e) { ; // } }
Example 2
Source File: JobSpecResolverTest.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@Test public void test() throws Exception { Config sysConfig = ConfigFactory.empty(); JobTemplate jobTemplate = Mockito.mock(JobTemplate.class); Mockito.when(jobTemplate.getResolvedConfig(Mockito.any(Config.class))).thenAnswer(i -> { Config userConfig = (Config) i.getArguments()[0]; return ConfigFactory.parseMap(ImmutableMap.of("template.value", "foo")).withFallback(userConfig); }); JobCatalogWithTemplates catalog = Mockito.mock(JobCatalogWithTemplates.class); Mockito.when(catalog.getTemplate(Mockito.eq(URI.create("my://template")))).thenReturn(jobTemplate); JobSpecResolver resolver = JobSpecResolver.builder(sysConfig).jobCatalog(catalog).build(); JobSpec jobSpec = JobSpec.builder() .withConfig(ConfigFactory.parseMap(ImmutableMap.of("key", "value"))) .withTemplate(URI.create("my://template")).build(); ResolvedJobSpec resolvedJobSpec = resolver.resolveJobSpec(jobSpec); Assert.assertEquals(resolvedJobSpec.getOriginalJobSpec(), jobSpec); Assert.assertEquals(resolvedJobSpec.getConfig().entrySet().size(), 2); Assert.assertEquals(resolvedJobSpec.getConfig().getString("key"), "value"); Assert.assertEquals(resolvedJobSpec.getConfig().getString("template.value"), "foo"); }
Example 3
Source File: CouchbaseWriterTest.java From incubator-gobblin with Apache License 2.0 | 6 votes |
/** * Test that a single Json document can be written successfully * @throws IOException * @throws DataConversionException * @throws ExecutionException * @throws InterruptedException */ @Test(groups={"timeout"}) public void testJsonDocumentWrite() throws IOException, DataConversionException, ExecutionException, InterruptedException { CouchbaseWriter writer = new CouchbaseWriter(_couchbaseEnvironment, ConfigFactory.empty()); try { String key = "hello"; String testContent = "hello world"; HashMap<String, String> contentMap = new HashMap<>(); contentMap.put("value", testContent); Gson gson = new Gson(); String jsonString = gson.toJson(contentMap); RawJsonDocument jsonDocument = RawJsonDocument.create(key, jsonString); writer.write(jsonDocument, null).get(); RawJsonDocument returnDoc = writer.getBucket().get(key, RawJsonDocument.class); Map<String, String> returnedMap = gson.fromJson(returnDoc.content(), Map.class); Assert.assertEquals(testContent, returnedMap.get("value")); } finally { writer.close(); } }
Example 4
Source File: FineGrainedWatermarkTrackerTest.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/** * Single threaded test that creates attempts, acknowledges a few at random * then checks if the getCommitables method is returning the right values. * Runs a few iterations. */ @Test public static void testWatermarkTracker() { Random random = new Random(); Config config = ConfigFactory.empty(); for (int j =0; j < 100; ++j) { FineGrainedWatermarkTracker tracker = new FineGrainedWatermarkTracker(config); int numWatermarks = 1 + random.nextInt(1000); AcknowledgableWatermark[] acknowledgableWatermarks = new AcknowledgableWatermark[numWatermarks]; for (int i = 0; i < numWatermarks; ++i) { CheckpointableWatermark checkpointableWatermark = new DefaultCheckpointableWatermark("default", new LongWatermark(i)); AcknowledgableWatermark ackable = new AcknowledgableWatermark(checkpointableWatermark); acknowledgableWatermarks[i] = ackable; tracker.track(ackable); } // Create some random holes. Don't fire acknowledgements for these messages. int numMissingAcks = random.nextInt(numWatermarks); SortedSet<Integer> holes = new TreeSet<>(); for (int i = 0; i < numMissingAcks; ++i) { holes.add(random.nextInt(numWatermarks)); } for (int i = 0; i < numWatermarks; ++i) { if (!holes.contains(i)) { acknowledgableWatermarks[i].ack(); } } verifyCommitables(tracker, holes, numWatermarks-1); // verify that sweeping doesn't have any side effects on correctness tracker.sweep(); verifyCommitables(tracker, holes, numWatermarks-1); } }
Example 5
Source File: FileBasedJobLockFactoryManagerTest.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Test public void testGetFactoryConfig() { FileBasedJobLockFactoryManager mgr = new FileBasedJobLockFactoryManager(); Config sysConfig1 = ConfigFactory.empty(); Assert.assertTrue(mgr.getFactoryConfig(sysConfig1).isEmpty()); Config sysConfig2 = sysConfig1.withValue("some.prop", ConfigValueFactory.fromAnyRef("test")); Assert.assertTrue(mgr.getFactoryConfig(sysConfig2).isEmpty()); Config sysConfig3 = sysConfig2.withValue(FileBasedJobLockFactoryManager.CONFIG_PREFIX + "." + FileBasedJobLockFactory.LOCK_DIR_CONFIG, ConfigValueFactory.fromAnyRef("/tmp")); Config factoryCfg3 = mgr.getFactoryConfig(sysConfig3); Assert.assertEquals(factoryCfg3.getString(FileBasedJobLockFactory.LOCK_DIR_CONFIG), "/tmp"); }
Example 6
Source File: ContainerHealthMetricsServiceTest.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Test public void testRunOneIteration() throws Exception { Config config = ConfigFactory.empty(); ContainerHealthMetricsService service = new ContainerHealthMetricsService(config); service.runOneIteration(); //Ensure lastGcStats updated after each iteration Assert.assertTrue(service.getCurrentGcStats() == service.getLastGcStats()); ContainerHealthMetricsService.GcStats previousLastGcStats = service.getLastGcStats(); Assert.assertTrue( service.minorGcCount.get() >= 0); Assert.assertTrue( service.minorGcDuration.get() >= 0); Assert.assertTrue( service.majorGcCount.get() >= 0); Assert.assertTrue( service.minorGcDuration.get() >= 0); Assert.assertTrue( service.unknownGcCount.get() >= 0); Assert.assertTrue( service.unknownGcDuration.get() >= 0); double processCpuTime1 = service.processCpuTime.get(); Thread.sleep(10); service.runOneIteration(); Assert.assertTrue(service.getCurrentGcStats() == service.getLastGcStats()); Assert.assertTrue(service.getLastGcStats() != previousLastGcStats); double processCpuTime2 = service.processCpuTime.get(); Assert.assertTrue( processCpuTime1 <= processCpuTime2); Assert.assertTrue( service.minorGcCount.get() >= 0); Assert.assertTrue( service.minorGcDuration.get() >= 0); Assert.assertTrue( service.majorGcCount.get() >= 0); Assert.assertTrue( service.minorGcDuration.get() >= 0); Assert.assertTrue( service.unknownGcCount.get() >= 0); Assert.assertTrue( service.unknownGcDuration.get() >= 0); }
Example 7
Source File: GobblinMultiTaskAttemptTest.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Test public void testRunWithTaskCreationFailure() throws Exception { // Preparing Instance of TaskAttempt with designed failure on task creation WorkUnit tmpWU = new WorkUnit(); // Put necessary attributes in workunit tmpWU.setProp(ConfigurationKeys.TASK_ID_KEY, "task_test"); List<WorkUnit> workUnit = ImmutableList.of(tmpWU); JobState jobState = new JobState(); // Limit the number of times of retry in task-creation. jobState.setProp(RETRY_TIME_OUT_MS, 1000); TaskStateTracker stateTrackerMock = Mockito.mock(TaskStateTracker.class); TaskExecutor taskExecutorMock = Mockito.mock(TaskExecutor.class); Config config = ConfigFactory.empty(); SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, GobblinScopeTypes.GLOBAL.defaultScopeInstance()); SharedResourcesBrokerImpl<GobblinScopeTypes> jobBroker = topBroker.newSubscopedBuilder(new JobScopeInstance("testJob", "job123")).build(); taskAttempt = new GobblinMultiTaskAttempt(workUnit.iterator(), "testJob", jobState, stateTrackerMock, taskExecutorMock, Optional.absent(), Optional.absent(), jobBroker); try { // This attempt will automatically fail due to missing required config in // org.apache.gobblin.runtime.TaskContext.getSource taskAttempt.run(); } catch (Exception e) { Assert.assertTrue(e instanceof IOException); return; } // Should never reach here. Assert.fail(); }
Example 8
Source File: ObjectStoreWriterTest.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Override public GetObjectResponse getObject(byte[] objectId) throws IOException { if (!this.store.containsKey(objectId)) { throw new IOException("Object not found " + objectId); } return new GetObjectResponse(IOUtils.toInputStream(this.store.get(objectId), "UTF-8"), ConfigFactory.empty()); }
Example 9
Source File: FlowConfigV2Test.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@BeforeClass public void setUp() throws Exception { ConfigBuilder configBuilder = ConfigBuilder.create(); _testDirectory = Files.createTempDir(); configBuilder .addPrimitive(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY, _testDirectory.getAbsolutePath()) .addPrimitive(FSSpecStore.SPECSTORE_FS_DIR_KEY, TEST_SPEC_STORE_DIR); cleanUpDir(TEST_SPEC_STORE_DIR); Config config = configBuilder.build(); final FlowCatalog flowCatalog = new FlowCatalog(config); flowCatalog.startAsync(); flowCatalog.awaitRunning(); _requesterService = new TestRequesterService(ConfigFactory.empty()); Injector injector = Guice.createInjector(new Module() { @Override public void configure(Binder binder) { binder.bind(FlowConfigsResourceHandler.class).annotatedWith(Names.named(FlowConfigsV2Resource.FLOW_CONFIG_GENERATOR_INJECT_NAME)).toInstance(new FlowConfigV2ResourceLocalHandler(flowCatalog)); // indicate that we are in unit testing since the resource is being blocked until flow catalog changes have // been made binder.bindConstant().annotatedWith(Names.named(FlowConfigsV2Resource.INJECT_READY_TO_USE)).to(Boolean.TRUE); binder.bind(RequesterService.class).annotatedWith(Names.named(FlowConfigsV2Resource.INJECT_REQUESTER_SERVICE)).toInstance(_requesterService); } }); _server = EmbeddedRestliServer.builder().resources( Lists.<Class<? extends BaseResource>>newArrayList(FlowConfigsV2Resource.class)).injector(injector).build(); _server.startAsync(); _server.awaitRunning(); _client = new FlowConfigV2Client(String.format("http://localhost:%s/", _server.getPort())); }
Example 10
Source File: ConfigLoader.java From casquatch with Apache License 2.0 | 5 votes |
/** * Get configuration for name. Returns empty if missing and logs values to trace * @param configName name of configuration * @return Config object */ private static Config getConfig(String configName) { if(root().hasPath(configName)) { log.debug("Loading {}",configName); Config newConfig = root().getConfig(configName); for (Map.Entry<String, ConfigValue> entry : newConfig.entrySet()) { log.debug("{}: {} -> {}",configName,entry.getKey(),entry.getValue().render()); } return newConfig; } else { log.trace("No values found for {}",configName); return ConfigFactory.empty(); } }
Example 11
Source File: TestDistinctDeriver.java From envelope with Apache License 2.0 | 5 votes |
@Test public void derive() throws Exception { Dataset<Row> source = createTestDataframe(); Map<String, Dataset<Row>> dependencies = Maps.newHashMap(); dependencies.put("df1", source); DistinctDeriver deriver = new DistinctDeriver(); Config config = ConfigFactory.empty(); assertNoValidationFailures(deriver, config); deriver.configure(config); List<Row> results = deriver.derive(dependencies).collectAsList(); assertEquals(results.size(), 11); assertTrue(results.containsAll(createTestData())); config = ConfigFactory.empty().withValue(DistinctDeriver.DISTINCT_STEP_CONFIG, ConfigValueFactory.fromAnyRef("df1")); deriver.configure(config); results = deriver.derive(dependencies).collectAsList(); assertEquals(results.size(), 11); assertTrue(results.containsAll(createTestData())); dependencies.put("df2", null); dependencies.put("df3", null); results = deriver.derive(dependencies).collectAsList(); assertEquals(results.size(), 11); assertTrue(results.containsAll(createTestData())); }
Example 12
Source File: FileBasedJobLockFactoryManager.java From incubator-gobblin with Apache License 2.0 | 4 votes |
@Override protected Config getFactoryConfig(Config sysConfig) { return sysConfig.hasPath(CONFIG_PREFIX) ? sysConfig.getConfig(CONFIG_PREFIX) : ConfigFactory.empty(); }
Example 13
Source File: FineGrainedWatermarkTrackerTest.java From incubator-gobblin with Apache License 2.0 | 4 votes |
/** * A concurrent test, attempts fired in a single thread, but acks come in from multiple threads, * out of order. * */ @Test public static void testConcurrentWatermarkTracker() throws IOException, InterruptedException { Random random = new Random(); ScheduledExecutorService ackingService = new ScheduledThreadPoolExecutor(100, ExecutorsUtils.defaultThreadFactory()); for (int j =0; j < 100; ++j) { FineGrainedWatermarkTracker tracker = new FineGrainedWatermarkTracker(ConfigFactory.empty()); tracker.start(); int numWatermarks = 1 + random.nextInt(1000); AcknowledgableWatermark[] acknowledgableWatermarks = new AcknowledgableWatermark[numWatermarks]; SortedSet<Integer> holes = new TreeSet<>(); final AtomicInteger numAcks = new AtomicInteger(0); for (int i = 0; i < numWatermarks; ++i) { CheckpointableWatermark checkpointableWatermark = new DefaultCheckpointableWatermark("default", new LongWatermark(i)); final AcknowledgableWatermark ackable = new AcknowledgableWatermark(checkpointableWatermark); tracker.track(ackable); acknowledgableWatermarks[i] = ackable; // ack or not boolean ack = random.nextBoolean(); if (ack) { numAcks.incrementAndGet(); long sleepTime = random.nextInt(100); ackingService.schedule(new Callable<Object>() { @Override public Object call() throws Exception { ackable.ack(); numAcks.decrementAndGet(); return null; } }, sleepTime, TimeUnit.MILLISECONDS); } else { holes.add(i); } } while (numAcks.get() != 0) { log.info("Waiting for " + numAcks.get() + " acks"); Thread.sleep(100); } verifyCommitables(tracker, holes, numWatermarks-1); tracker.close(); } }
Example 14
Source File: QuartzJobSpecScheduler.java From incubator-gobblin with Apache License 2.0 | 4 votes |
public QuartzJobSpecScheduler(Logger log) { this(Optional.of(log), ConfigFactory.empty(), Optional.<SchedulerService>absent()); }
Example 15
Source File: FsCleanableHelperTest.java From incubator-gobblin with Apache License 2.0 | 4 votes |
@Test public void testDeleteEmptyDirs() throws Exception { Properties props = new Properties(); props.setProperty(FsCleanableHelper.SKIP_TRASH_KEY, Boolean.toString(true)); FsCleanableHelper fsCleanableHelper = new FsCleanableHelper(this.fs, props, ConfigFactory.empty(), log); FileSystemDataset fsDataset = mock(FileSystemDataset.class); Path datasetRoot = new Path(testTempPath, "dataset1"); when(fsDataset.datasetRoot()).thenReturn(datasetRoot); // To delete Path deleted1 = new Path(datasetRoot, "2016/01/01/13"); Path deleted2 = new Path(datasetRoot, "2016/01/01/14"); Path deleted3 = new Path(datasetRoot, "2016/01/02/15"); // Do not delete Path notDeleted1 = new Path(datasetRoot, "2016/01/02/16"); this.fs.mkdirs(deleted1); this.fs.mkdirs(deleted2); this.fs.mkdirs(deleted3); this.fs.mkdirs(notDeleted1); // Make sure all paths are created Assert.assertTrue(this.fs.exists(deleted1)); Assert.assertTrue(this.fs.exists(deleted2)); Assert.assertTrue(this.fs.exists(deleted3)); Assert.assertTrue(this.fs.exists(notDeleted1)); List<FileSystemDatasetVersion> deletableVersions = ImmutableList.<FileSystemDatasetVersion> of( new MockFileSystemDatasetVersion(deleted1), new MockFileSystemDatasetVersion(deleted2), new MockFileSystemDatasetVersion(deleted3)); fsCleanableHelper.clean(deletableVersions, fsDataset); // Verify versions are deleted Assert.assertFalse(this.fs.exists(deleted1)); Assert.assertFalse(this.fs.exists(deleted2)); Assert.assertFalse(this.fs.exists(deleted3)); // Verify versions are not deleted Assert.assertTrue(this.fs.exists(notDeleted1)); // Verify empty parent dir "2016/01/01" is deleted Assert.assertFalse(this.fs.exists(deleted1.getParent())); // Verify non empty parent dir "2016/01/02" exists Assert.assertTrue(this.fs.exists(notDeleted1.getParent())); }
Example 16
Source File: EventTimeUpsertPlanner.java From envelope with Apache License 2.0 | 4 votes |
private Config getEventTimeModelConfig() { return config.hasPath(EVENT_TIME_MODEL_CONFIG_NAME) ? config.getConfig(EVENT_TIME_MODEL_CONFIG_NAME) : ConfigFactory.empty(); }
Example 17
Source File: ConfigUtilTest.java From styx with Apache License 2.0 | 4 votes |
@Test public void getShouldReturnEmpty() { final Config config = ConfigFactory.empty(); assertThat(ConfigUtil.get(config, config::getString, "foo.bar"), is(Optional.empty())); }
Example 18
Source File: NoopDynamicConfigGenerator.java From incubator-gobblin with Apache License 2.0 | 4 votes |
public Config generateDynamicConfig(Config config) { return ConfigFactory.empty(); }
Example 19
Source File: Server.java From xrpc with Apache License 2.0 | 2 votes |
/** * Construct a server with configured port. If the port is < 0, the port will be taken from * configuration. If it is 0, the system will pick up an ephemeral port. */ public Server(int port) { this(new XConfig(ConfigFactory.empty()), port); }
Example 20
Source File: XConfig.java From xrpc with Apache License 2.0 | 2 votes |
/** * Construct a config object using the default configuration values <a * href="https://github.com/Nordstrom/xrpc/blob/master/src/main/resources/com/nordstrom/xrpc/xrpc.conf">here</a>. */ public XConfig() { this(ConfigFactory.empty()); }