@Override public void setUp() throws Exception { super.setUp(); RepTestUtils.removeRepEnvironments(envRoot); }
/** Test the basic configuration of LogFlusher. */ @Test public void testBasicConfig() throws Throwable { try { EnvironmentConfig envConfig = RepTestUtils.createEnvConfig(Durability.COMMIT_NO_SYNC); ReplicationConfig repConfig = new ReplicationConfig(); repConfig.setConfigParam(ReplicationMutableConfig.LOG_FLUSH_TASK_INTERVAL, "30 s"); repEnvInfo = RepTestUtils.setupEnvInfos(envRoot, 3, envConfig, repConfig); RepTestUtils.joinGroup(repEnvInfo); assertTrue(repEnvInfo[0].isMaster()); /* Check the LogFlusher configuration. */ TimerTask[] oldTasks = new TimerTask[repEnvInfo.length]; for (int i = 0; i < repEnvInfo.length; i++) { LogFlusher flusher = repEnvInfo[i].getRepNode().getLogFlusher(); oldTasks[i] = flusher.getFlushTask(); assertTrue(flusher != null); assertTrue(flusher.getFlushTask() != null); assertTrue(flusher.getFlushInterval() == 30000); } /* Check that those configuratins are mutable. */ repConfig.setConfigParam(ReplicationMutableConfig.LOG_FLUSH_TASK_INTERVAL, "50 s"); for (int i = 0; i < repEnvInfo.length; i++) { repEnvInfo[i].getEnv().setRepMutableConfig(repConfig); } for (int i = 0; i < repEnvInfo.length; i++) { LogFlusher flusher = repEnvInfo[i].getRepNode().getLogFlusher(); assertTrue(flusher != null); assertTrue(flusher.getFlushTask() != null); assertTrue(flusher.getFlushTask() != oldTasks[i]); assertTrue(flusher.getFlushInterval() == 50000); } repConfig.setConfigParam(ReplicationMutableConfig.RUN_LOG_FLUSH_TASK, "false"); for (int i = 0; i < repEnvInfo.length; i++) { repEnvInfo[i].getEnv().setRepMutableConfig(repConfig); } for (int i = 0; i < repEnvInfo.length; i++) { LogFlusher flusher = repEnvInfo[i].getRepNode().getLogFlusher(); assertTrue(flusher != null); assertTrue(flusher.getFlushTask() == null); } RepTestUtils.shutdownRepEnvs(repEnvInfo); RepTestUtils.removeRepEnvironments(envRoot); repConfig.setConfigParam(ReplicationConfig.RUN_LOG_FLUSH_TASK, "false"); repEnvInfo = RepTestUtils.setupEnvInfos(envRoot, 3, envConfig, repConfig); RepTestUtils.joinGroup(repEnvInfo); /* Check that the task is disabled. */ for (int i = 0; i < repEnvInfo.length; i++) { assertTrue(repEnvInfo[i].getRepNode().getLogFlusher() == null); } } catch (Throwable t) { t.printStackTrace(); throw t; } finally { RepTestUtils.shutdownRepEnvs(repEnvInfo); } }