2015-04-07 07:51:44 +02:00
|
|
|
/*
|
2015-08-08 19:36:14 +02:00
|
|
|
* Copyright (c) 2012-2015 The original author or authors
|
2015-04-07 07:51:44 +02:00
|
|
|
* ------------------------------------------------------
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
|
* and Apache License v2.0 which accompanies this distribution.
|
|
|
|
|
*
|
|
|
|
|
* The Eclipse Public License is available at
|
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
*
|
|
|
|
|
* The Apache License v2.0 is available at
|
|
|
|
|
* http://www.opensource.org/licenses/apache2.0.php
|
|
|
|
|
*
|
|
|
|
|
* You may elect to redistribute this code under either of these licenses.
|
|
|
|
|
*/
|
2015-11-20 20:54:27 +01:00
|
|
|
package io.moquette.server;
|
2015-04-07 07:51:44 +02:00
|
|
|
|
2015-11-20 20:54:27 +01:00
|
|
|
import io.moquette.server.config.IConfig;
|
2015-11-08 18:25:55 +01:00
|
|
|
|
2015-04-07 07:51:44 +02:00
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
2015-12-08 14:04:35 +01:00
|
|
|
import static io.moquette.BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
|
|
|
|
|
import static io.moquette.BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME;
|
2016-05-18 00:09:40 +02:00
|
|
|
import static io.moquette.BrokerConstants.PORT_PROPERTY_NAME;
|
2015-11-08 18:25:55 +01:00
|
|
|
import static org.junit.Assert.assertFalse;
|
2015-04-07 07:51:44 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Used to carry integration configurations.
|
|
|
|
|
*
|
|
|
|
|
* Created by andrea on 4/7/15.
|
|
|
|
|
*/
|
2015-11-08 18:25:55 +01:00
|
|
|
public class IntegrationUtils {
|
2015-04-07 07:51:44 +02:00
|
|
|
static String localMapDBPath() {
|
|
|
|
|
String currentDir = System.getProperty("user.dir");
|
|
|
|
|
return currentDir + File.separator + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 12:09:10 +02:00
|
|
|
static String localClusterMapDBPath(int port) {
|
|
|
|
|
String currentDir = System.getProperty("user.dir");
|
|
|
|
|
return currentDir + File.separator + port + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 00:09:40 +02:00
|
|
|
public static Properties prepareTestProperties() {
|
2015-04-07 07:51:44 +02:00
|
|
|
Properties testProperties = new Properties();
|
|
|
|
|
testProperties.put(PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath());
|
2016-05-18 00:09:40 +02:00
|
|
|
testProperties.put(PORT_PROPERTY_NAME, "1883");
|
2015-04-07 07:51:44 +02:00
|
|
|
return testProperties;
|
|
|
|
|
}
|
2015-11-08 18:25:55 +01:00
|
|
|
|
2016-07-22 12:09:10 +02:00
|
|
|
public static Properties prepareTestClusterProperties(int port) {
|
|
|
|
|
Properties testProperties = new Properties();
|
|
|
|
|
testProperties.put(PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localClusterMapDBPath(port));
|
|
|
|
|
testProperties.put(PORT_PROPERTY_NAME, Integer.toString(port));
|
|
|
|
|
return testProperties;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-08 18:25:55 +01:00
|
|
|
public static void cleanPersistenceFile(IConfig config) {
|
|
|
|
|
String fileName = config.getProperty(PERSISTENT_STORE_PROPERTY_NAME);
|
|
|
|
|
cleanPersistenceFile(fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void cleanPersistenceFile(String fileName) {
|
|
|
|
|
File dbFile = new File(fileName);
|
|
|
|
|
if (dbFile.exists()) {
|
|
|
|
|
dbFile.delete();
|
|
|
|
|
new File(fileName + ".p").delete();
|
|
|
|
|
new File(fileName + ".t").delete();
|
|
|
|
|
}
|
|
|
|
|
assertFalse(dbFile.exists());
|
|
|
|
|
}
|
2015-04-07 07:51:44 +02:00
|
|
|
}
|