Merge pull request #1333 from himanshug/convert_props_ut

UTs for ConvertProperties
This commit is contained in:
Xavier Léauté 2015-05-03 15:11:53 -07:00
commit 2ec87838d2
6 changed files with 169 additions and 3 deletions

View File

@ -151,8 +151,6 @@ These properties specify the jdbc connection and other configuration around the
|`druid.metadata.storage.connector.user`|The username to connect with.|none| |`druid.metadata.storage.connector.user`|The username to connect with.|none|
|`druid.metadata.storage.connector.password`|The password to connect with.|none| |`druid.metadata.storage.connector.password`|The password to connect with.|none|
|`druid.metadata.storage.connector.createTables`|If Druid requires a table and it doesn't exist, create it?|true| |`druid.metadata.storage.connector.createTables`|If Druid requires a table and it doesn't exist, create it?|true|
|`druid.metadata.storage.connector.useValidationQuery`|Validate a table with a query.|false|
|`druid.metadata.storage.connector.validationQuery`|The query to validate with.|SELECT 1|
|`druid.metadata.storage.tables.base`|The base name for tables.|druid| |`druid.metadata.storage.tables.base`|The base name for tables.|druid|
|`druid.metadata.storage.tables.segmentTable`|The table to use to look for segments.|druid_segments| |`druid.metadata.storage.tables.segmentTable`|The table to use to look for segments.|druid_segments|
|`druid.metadata.storage.tables.ruleTable`|The table to use to look for segment load/drop rules.|druid_rules| |`druid.metadata.storage.tables.ruleTable`|The table to use to look for segment load/drop rules.|druid_rules|

View File

@ -68,7 +68,16 @@ public class ConvertProperties implements Runnable
new Rename("druid.db.connector.connectURI", "druid.metadata.storage.connector.connectURI"), new Rename("druid.db.connector.connectURI", "druid.metadata.storage.connector.connectURI"),
new Rename("druid.db.connector.user", "druid.metadata.storage.connector.user"), new Rename("druid.db.connector.user", "druid.metadata.storage.connector.user"),
new Rename("druid.db.connector.password", "druid.metadata.storage.connector.password"), new Rename("druid.db.connector.password", "druid.metadata.storage.connector.password"),
new Remove("druid.db.connector.validationQuery"),
new Remove("druid.db.connector.useValidationQuery"),
new Rename("druid.db.connector.createTables", "druid.metadata.storage.connector.createTables"),
new Rename("druid.db.tables.base", "druid.metadata.storage.tables.base"), new Rename("druid.db.tables.base", "druid.metadata.storage.tables.base"),
new Rename("druid.db.tables.configTable", "druid.metadata.storage.tables.configTable"),
new Rename("druid.db.tables.segmentTable", "druid.metadata.storage.tables.segmentTable"),
new Rename("druid.db.tables.ruleTable", "druid.metadata.storage.tables.ruleTable"),
new Rename("druid.db.tables.taskLock", "druid.metadata.storage.tables.taskLock"),
new Rename("druid.db.tables.tasks", "druid.metadata.storage.tables.tasks"),
new Rename("druid.db.tables.taskLog", "druid.metadata.storage.tables.taskLog"),
new PropertyConverter() new PropertyConverter()
{ {
// Add a new config for metadata storage type, and update property name // Add a new config for metadata storage type, and update property name
@ -124,7 +133,7 @@ public class ConvertProperties implements Runnable
); );
} }
catch (IOException e) { catch (IOException e) {
throw com.google.api.client.repackaged.com.google.common.base.Throwables.propagate(e); throw Throwables.propagate(e);
} }
coordinates.addAll(oldCoordinates); coordinates.addAll(oldCoordinates);
coordinates.add(String.format("io.druid.extensions:%s-metadata-storage", parseJdbcUrl(jdbcUrl))); coordinates.add(String.format("io.druid.extensions:%s-metadata-storage", parseJdbcUrl(jdbcUrl)));

View File

@ -0,0 +1,47 @@
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets licenses this file
* to you 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. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.druid.cli.convert;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Properties;
public class Remove implements PropertyConverter
{
private final String propertyToRemove;
public Remove(String propertyToRemove)
{
this.propertyToRemove = propertyToRemove;
}
@Override
public boolean canHandle(String property)
{
return this.propertyToRemove.equals(property);
}
@Override
public Map<String, String> convert(Properties properties)
{
return ImmutableMap.of();
}
}

View File

@ -0,0 +1,71 @@
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets licenses this file
* to you 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. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.druid.cli.convert;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.Rule;
import io.airlift.command.Cli;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class ConvertPropertiesTest
{
@Rule
public TemporaryFolder tmpFolder = new TemporaryFolder();
@Test
public void testConvertProperties() throws IOException
{
String oldPropertiesFile = this.getClass().getResource("/convertProps/old.properties").getFile();
File convertedPropertiesFile = tmpFolder.newFile();
Cli<?> parser = Cli.builder("convertProps")
.withCommand(ConvertProperties.class)
.build();
Object command = parser.parse("convertProps","-f", oldPropertiesFile,"-o", convertedPropertiesFile.getAbsolutePath());
Assert.assertNotNull(command);
ConvertProperties convertProperties = (ConvertProperties) command;
convertProperties.run();
Properties actualConvertedProperties = new Properties();
actualConvertedProperties.load(new FileInputStream(convertedPropertiesFile));
Properties expectedConvertedProperties = new Properties();
expectedConvertedProperties.load(this.getClass().getResourceAsStream("/convertProps/new.properties"));
Assert.assertEquals(expectedConvertedProperties, actualConvertedProperties);
}
@After
public void tearDown() throws IOException
{
FileUtils.deleteDirectory(tmpFolder.getRoot());
}
}

View File

@ -0,0 +1,20 @@
druid.metadata.storage.type=mysql
druid.metadata.storage.connector.connectURI=jdbc:mysql://localhost:3306/druid
druid.metadata.storage.connector.createTables=true
druid.metadata.storage.connector.password=diurd
druid.metadata.storage.connector.user=druid
druid.metadata.storage.tables.base=druid
druid.metadata.storage.tables.segmentTable=druid_segments
druid.metadata.storage.tables.ruleTable=druid_rules
druid.metadata.storage.tables.configTable=druid_config
druid.metadata.storage.tables.tasks=druid_tasks
druid.metadata.storage.tables.taskLog=druid_taskLog
druid.metadata.storage.tables.taskLock=druid_taskLock
druid.indexer.storage.type=metadata
druid.publish.type=metadata
druid.extensions.coordinates=["io.druid.extensions:mysql-metadata-storage"]
leave.me.alone=xxx

View File

@ -0,0 +1,21 @@
druid.db.connector.connectURI=jdbc:mysql://localhost:3306/druid
druid.db.connector.createTables=true
druid.db.connector.password=diurd
druid.db.connector.user=druid
druid.db.connector.useValidationQuery=false
druid.db.connector.validationQuery=SELECT 1
druid.db.tables.base=druid
druid.db.tables.segmentTable=druid_segments
druid.db.tables.ruleTable=druid_rules
druid.db.tables.configTable=druid_config
druid.db.tables.tasks=druid_tasks
druid.db.tables.taskLog=druid_taskLog
druid.db.tables.taskLock=druid_taskLock
druid.indexer.storage.type=db
druid.publish.type=db
druid.extensions.coordinates=[]
leave.me.alone=xxx