2016-10-19 17:08:07 -07:00
|
|
|
/**
|
|
|
|
* Copyright 2015 LinkedIn Corp. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
*/
|
2016-05-30 11:09:36 +02:00
|
|
|
package actors;
|
|
|
|
|
|
|
|
import com.google.common.io.Files;
|
2017-03-25 20:39:37 -07:00
|
|
|
import java.util.List;
|
2016-05-30 11:09:36 +02:00
|
|
|
import metadata.etl.models.EtlJobName;
|
|
|
|
import org.junit.Test;
|
|
|
|
import wherehows.common.Constant;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
2017-02-24 10:14:47 -08:00
|
|
|
import static org.fest.assertions.api.Assertions.*;
|
2016-05-30 11:09:36 +02:00
|
|
|
|
|
|
|
public class ConfigUtilTest {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldGenerateEtlJobDefaultCommand() {
|
|
|
|
// when:
|
2017-04-27 16:43:18 -07:00
|
|
|
ProcessBuilder pb =
|
|
|
|
ConfigUtil.buildProcess(EtlJobName.HADOOP_DATASET_METADATA_ETL, 0L, null, new Properties());
|
2016-05-30 11:09:36 +02:00
|
|
|
|
|
|
|
// then:
|
2017-04-27 16:43:18 -07:00
|
|
|
assertThat(pb.command()).contains("java", "-cp", System.getProperty("java.class.path"),
|
2017-03-25 20:39:37 -07:00
|
|
|
"-Dconfig=/var/tmp/wherehows/exec/0.properties", "-DCONTEXT=HADOOP_DATASET_METADATA_ETL",
|
|
|
|
"-Dlogback.configurationFile=etl_logback.xml", "metadata.etl.Launcher");
|
2016-05-30 11:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldGenerateEtlJobCommandWithConfiguredDirectory() {
|
2017-04-27 16:43:18 -07:00
|
|
|
final String applicationDirectory = "./temp";
|
2016-05-30 11:09:36 +02:00
|
|
|
|
|
|
|
// given:
|
|
|
|
Properties etlJobProperties = new Properties();
|
|
|
|
etlJobProperties.put(Constant.WH_APP_FOLDER_KEY, applicationDirectory);
|
|
|
|
|
|
|
|
// when:
|
2017-04-27 16:43:18 -07:00
|
|
|
ProcessBuilder pb = ConfigUtil.buildProcess(EtlJobName.LDAP_USER_ETL, 1L, " -a -b ", etlJobProperties);
|
2016-05-30 11:09:36 +02:00
|
|
|
|
|
|
|
// then:
|
2017-04-27 16:43:18 -07:00
|
|
|
assertThat(pb.command()).contains("java", "-a", "-b", "-cp", System.getProperty("java.class.path"),
|
2017-03-25 20:39:37 -07:00
|
|
|
"-Dconfig=" + applicationDirectory + "/exec/1.properties", "-DCONTEXT=LDAP_USER_ETL",
|
2017-04-19 16:04:38 -07:00
|
|
|
"-DLOG_DIR=" + applicationDirectory, "-Dlogback.configurationFile=etl_logback.xml",
|
|
|
|
"metadata.etl.Launcher");
|
2017-04-27 16:43:18 -07:00
|
|
|
assertThat(pb.redirectError().file().getPath().equals("./temp/LDAP_USER_ETL.stderr"));
|
|
|
|
assertThat(pb.redirectOutput().file().getPath().equals("./temp/LDAP_USER_ETL.stdout"));
|
2016-05-30 11:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldGeneratePropertiesWithValues() throws IOException {
|
|
|
|
final long whEtlExecId = System.currentTimeMillis();
|
|
|
|
final Properties etlJobProperties = new Properties();
|
|
|
|
etlJobProperties.put("p1", "v1");
|
|
|
|
etlJobProperties.put("p2", "v2");
|
|
|
|
etlJobProperties.put("p3", "v3");
|
|
|
|
|
|
|
|
final File propertiesFile = createTemporaryPropertiesFile(whEtlExecId, etlJobProperties);
|
|
|
|
|
|
|
|
// when:
|
2017-02-24 10:14:47 -08:00
|
|
|
ConfigUtil.generateProperties(EtlJobName.HIVE_DATASET_METADATA_ETL, 2, whEtlExecId, etlJobProperties);
|
2016-05-30 11:09:36 +02:00
|
|
|
|
|
|
|
// then:
|
|
|
|
final String content = Files.toString(propertiesFile, Charset.defaultCharset());
|
2016-05-30 12:39:15 +02:00
|
|
|
assertThat(content)
|
|
|
|
.contains("p1=v1")
|
|
|
|
.contains("p2=v2")
|
|
|
|
.contains("p3=v3");
|
2016-05-30 11:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldGeneratePropertiesFileAndDeleteIt() throws IOException {
|
|
|
|
final long whEtlExecId = System.currentTimeMillis();
|
|
|
|
final Properties etlJobProperties = new Properties();
|
|
|
|
|
|
|
|
final File propertiesFile = createTemporaryPropertiesFile(whEtlExecId, etlJobProperties);
|
|
|
|
|
|
|
|
// expect:
|
2016-05-30 12:39:15 +02:00
|
|
|
assertThat(propertiesFile).doesNotExist();
|
2016-05-30 11:09:36 +02:00
|
|
|
|
|
|
|
// when:
|
|
|
|
final EtlJobName etlJobName = EtlJobName.valueOf("AZKABAN_EXECUTION_METADATA_ETL");
|
|
|
|
ConfigUtil.generateProperties(etlJobName, 2, whEtlExecId, etlJobProperties);
|
|
|
|
|
|
|
|
// then:
|
2016-05-30 12:39:15 +02:00
|
|
|
assertThat(propertiesFile).exists();
|
2016-05-30 11:09:36 +02:00
|
|
|
|
|
|
|
// when:
|
|
|
|
ConfigUtil.deletePropertiesFile(etlJobProperties, whEtlExecId);
|
|
|
|
|
|
|
|
// then:
|
2016-05-30 12:39:15 +02:00
|
|
|
assertThat(propertiesFile).doesNotExist();
|
2016-05-30 11:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private File createTemporaryPropertiesFile(long whEtlExecId, Properties etlJobProperties) {
|
2017-04-21 15:50:35 -07:00
|
|
|
final File tempDir = new File(Files.createTempDir(), "non-exsiting-dir");
|
2016-05-30 11:09:36 +02:00
|
|
|
tempDir.deleteOnExit();
|
|
|
|
final String tempDirPath = tempDir.getAbsolutePath();
|
|
|
|
|
|
|
|
etlJobProperties.put(Constant.WH_APP_FOLDER_KEY, tempDirPath);
|
|
|
|
|
|
|
|
return new File(tempDirPath + "/exec", whEtlExecId + ".properties");
|
|
|
|
}
|
|
|
|
}
|