@Override public Void call() { synchronized (currentConfigMutex) { currentConfig = config; saveToDisk(config); } return null; } }, ParseExecutors.io());
@Test public void testGetCurrentConfigAsyncSuccessCurrentConfigNotSetDiskConfigExist() throws Exception { File configFile = new File(temporaryFolder.getRoot(), "config"); ParseCurrentConfigController currentConfigController = new ParseCurrentConfigController(configFile); // Save sample ParseConfig to disk final Map<String, Object> sampleConfigParameters = new HashMap<String, Object>() {{ put("string", "value"); }}; JSONObject sampleConfigJson = new JSONObject() {{ put("params", NoObjectsEncoder.get().encode(sampleConfigParameters)); }}; ParseConfig diskConfig = ParseConfig.decode(sampleConfigJson, ParseDecoder.get()); currentConfigController.saveToDisk(diskConfig); // Verify before set, disk config exist and in memory config is null assertTrue(configFile.exists()); assertNull(currentConfigController.currentConfig); Task<ParseConfig> getTask = currentConfigController.getCurrentConfigAsync(); ParseTaskUtils.wait(getTask); ParseConfig config = getTask.getResult(); // Verify after set, in memory config is set and value is correct assertSame(config, currentConfigController.currentConfig); assertEquals("value", config.get("string")); assertEquals(1, config.getParams().size()); }
ParseCurrentConfigController currentConfigController = new ParseCurrentConfigController(configFile); currentConfigController.saveToDisk(config);
ParseCurrentConfigController currentConfigController = new ParseCurrentConfigController(configFile); currentConfigController.saveToDisk(config);