Skip to content

Commit

Permalink
Merge pull request #106 from rwth-acis/dbImprovements
Browse files Browse the repository at this point in the history
improve DB configuration
  • Loading branch information
beka-zhvania authored Feb 26, 2023
2 parents d6704d6 + b447f7e commit 59cc32e
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 105 deletions.
4 changes: 2 additions & 2 deletions ocd/arangoDB/config.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Sep 14 15:39:01 CEST 2022
PORT=8529
PASSWORD=password
DATABASENAME=ocd_db
DATABASENAME=ocdDB
TESTDATABASENAME=testDB
HOST=127.0.0.1
USER=root
6 changes: 0 additions & 6 deletions ocd/arangoDB/config_test.properties

This file was deleted.

6 changes: 0 additions & 6 deletions ocd/arangoDB/standard_config.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ protected void initResources() {
}

public ServiceClass() {
DatabaseConfig.setConfigFile(false); //TODO angeben ob test datenbank oder hauptdatenbank gewaehlt wird
database = new Database();

database = new Database(false);
setFieldValues();
// instantiate inactivityHandler to regularly remove content of inactive users.
inactivityHandler = new InactivityHandler(database, threadHandler, this); //TODO inactivity handler muss sich auf db beziehens
Expand All @@ -164,6 +164,7 @@ public ServiceClass() {

}


///////////////////////////////////////////////////////////
///// ATTRIBUTES
///////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ public void run() {
CoverId coverId = new CoverId(cKey, graphId);

RequestHandler requestHandler = new RequestHandler();

DatabaseConfig.setConfigFile(false);
Database database = new Database();

Database database = new Database(false);
try {
Cover c = database.getCover(user, gKey, cKey);
if(c == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ public void run() {
CentralityMapId id = new CentralityMapId(mKey, graphId);

RequestHandler requestHandler = new RequestHandler();

DatabaseConfig.setConfigFile(false);
Database database = new Database();

Database database = new Database(false);
try {
CentralityMap m = database.getCentralityMap(user, gKey, mKey);
if(m == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ public void run() {
CentralityMapId id = new CentralityMapId(mKey, graphId);

RequestHandler requestHandler = new RequestHandler();

DatabaseConfig.setConfigFile(false);
Database database = new Database();

Database database = new Database(false);
try {
CentralityMap m = database.getCentralityMap(user, gKey, mKey);
if(m == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,23 @@ public class Database {
private List<String> collectionNames =new ArrayList<String>(13);


public Database() {
public Database(boolean testDB) {
Properties props = DBC.getConfigProperties();
HOST = props.getProperty("HOST");
String port = props.getProperty("PORT");
PORT = Integer.parseInt(props.getProperty("PORT"));
USER = props.getProperty("USER");
PASSWORD = props.getProperty("PASSWORD");
DBNAME_STRING = props.getProperty("DATABASENAME");
if(!testDB) {
DBNAME_STRING = props.getProperty("DATABASENAME");
}else{
DBNAME_STRING = props.getProperty("TESTDATABASENAME");
}
DBNAME = DbName.of(DBNAME_STRING);
arangoDB = new ArangoDB.Builder().host(HOST, PORT).password(PASSWORD).serializer(new ArangoJack()).build();
arangoDB = new ArangoDB.Builder()
.host(HOST, PORT)
.user(USER)
.password(PASSWORD).serializer(new ArangoJack()).build();
db = arangoDB.db(DBNAME);
init();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,12 @@
import java.io.FileInputStream;

public class DatabaseConfig {
private static final String PATH = "./ocd/arangoDB/";

private static final String PATH = "ocd/arangoDB/";
private static final String FILENAME = "config.properties";
private static final String TESTFILENAME = "config_test.properties";
private static final String STANDARD_CONFIG_FILENAME = "standard_config.properties";
private static final File CONFIG_FILE = new File(PATH+FILENAME);
private static final File TESTFILE = new File(PATH + TESTFILENAME);
private static final File STANDARD_CONFIG_FILE = new File(PATH + STANDARD_CONFIG_FILENAME);
private static Properties props = new Properties();


public static void setConfigFile(boolean testFile) {
FileInputStream inputStream;
props.clear();
try {
if(testFile) {
inputStream = new FileInputStream(TESTFILE);
}
else {
inputStream = new FileInputStream(STANDARD_CONFIG_FILE);
}
props.load(inputStream);
}catch(IOException e) {
e.printStackTrace();
}
try {
FileOutputStream outputStream = new FileOutputStream(CONFIG_FILE);
props.store(outputStream, null);
outputStream.close();
}catch(IOException e) {
e.printStackTrace();
}
}

public Properties getConfigProperties() {
try {
FileInputStream inputStream = new FileInputStream(CONFIG_FILE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ public void run() {
* Set algorithm and benchmark status to running.
*/
RequestHandler requestHandler = new RequestHandler();

DatabaseConfig.setConfigFile(false);
Database database = new Database();

Database database = new Database(false);

String cKey = coverId.getKey();
CustomGraphId gId = coverId.getGraphId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public void run() {
* Set metric state to running.
*/
RequestHandler requestHandler = new RequestHandler();
DatabaseConfig.setConfigFile(false);
Database database = new Database();
Database database = new Database(false);

try {
OcdMetricLog persistedLog = database.getOcdMetricLog(logId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public void run() {
* Set metric state to running.
*/
RequestHandler requestHandler = new RequestHandler();
DatabaseConfig.setConfigFile(false);
Database database = new Database();
Database database = new Database(false);
try {
OcdMetricLog persistedLog = database.getOcdMetricLog(logId);
if(persistedLog == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public class ThreadHandler {
private static Database database;

public ThreadHandler() {
DatabaseConfig.setConfigFile(false);
database = new Database();
database = new Database(false);
}
/**
* Runs an algorithm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public class ServiceDatabaseTest {

@BeforeClass
public static void clearDatabase() {
DatabaseConfig.setConfigFile(true);
database = new Database();
database = new Database(true);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ public class ServiceTest {

private static final String testServiceClass = "i5.las2peer.services.ocd.ServiceClass";
private static final String mainPath = "ocd/";
private static long SawmillGraphId;
private static String SawmillGraphKey;
private static long DolphinsGraphId;
private static String DolphinsGraphKey;
private static long AperiodicTwoCommunitiesGraphId;
private static String AperiodicTwoCommunitiesGraphKey;

private static Database database;
Expand Down Expand Up @@ -127,8 +124,7 @@ private static void setupDatabase() throws AdapterException, FileNotFoundExcepti
/*
* Set db content
*/
DatabaseConfig.setConfigFile(false);
database = new Database();
database = new Database(false);
CustomGraph graph = OcdTestGraphFactory.getAperiodicTwoCommunitiesGraph();
createGraph(graph);
AperiodicTwoCommunitiesGraphKey = graph.getKey();
Expand Down Expand Up @@ -319,7 +315,7 @@ public void getSimulation() throws AdapterException, FileNotFoundException {
s1.setName("name");
String id1 = "0";
SimulationSeries s2 = new SimulationSeries();
s1.setName("name2");
s2.setName("name2");
String id2 = "0";

try {
Expand All @@ -332,8 +328,9 @@ public void getSimulation() throws AdapterException, FileNotFoundException {

try {
c.setLogin(testAgent.getIdentifier(), testPass);
ClientResponse result;

ClientResponse result = c.sendRequest("GET",
result = c.sendRequest("GET",
mainPath + "simulation/" + 124, "");
System.out.println("Result of 'getSimulation' " + result.getResponse().trim());
String resultString = result.getResponse().trim(); // trimmed response string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public class SimulationPersistenceTest {

@BeforeClass
public static void clearDatabase() {
DatabaseConfig.setConfigFile(true);
database = new Database();
database = new Database(true);
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public class CoverDatabaseTest {

@BeforeClass
public static void clearDatabase() {
DatabaseConfig.setConfigFile(true);
database = new Database();
database = new Database(true);
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public class CustomGraphDatabaseTest {

@BeforeClass
public static void clearDatabase() {
DatabaseConfig.setConfigFile(true);
database = new Database();
database = new Database(true);
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@
import org.junit.Ignore;
import org.junit.Test;

@Ignore
public class DatabaseConfigTest {
private static DatabaseConfig dc = new DatabaseConfig();

@Test
public void test() {
System.out.println("config before dbconfigtest : " + dc.getConfigProperties().toString());
DatabaseConfig.setConfigFile(false);
System.out.println("config after the main (non-test) database was set : " + dc.getConfigProperties().toString());
}



@Test
Expand All @@ -27,14 +20,18 @@ public void getPropertiesTest() {
System.out.println("PORT:"+props.getProperty("PORT"));
assertEquals("8529", props.getProperty("PORT"));

System.out.println("USER:"+props.getProperty("USER"));
assertEquals("root", props.getProperty("USER"));
// System.out.println("USER:"+props.getProperty("USER"));
// assertEquals("root", props.getProperty("USER"));

System.out.println("PASSWORD:"+props.getProperty("PASSWORD"));
assertEquals("password", props.getProperty("PASSWORD"));
// System.out.println("PASSWORD:"+props.getProperty("PASSWORD"));
// assertEquals("password", props.getProperty("PASSWORD"));

System.out.println("DATABASENAME:"+props.getProperty("DATABASENAME"));
assertEquals("ocd_db", props.getProperty("DATABASENAME"));
String dbName = props.getProperty("DATABASENAME");
assertEquals("ocdDB",dbName );

System.out.println("TESTDATABASENAME:"+props.getProperty("TESTDATABASENAME"));
assertEquals("testDB", props.getProperty("TESTDATABASENAME"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public class DatabaseMethodTest {

@BeforeClass
public static void setupTestDatabase() {
DatabaseConfig.setConfigFile(true);
database = new Database();
database = new Database(true);

}
@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public class DatabaseTest {

@BeforeClass
public static void clearDatabase() {
DatabaseConfig.setConfigFile(true);
database = new Database();
database = new Database(true);
}

@AfterClass
Expand All @@ -56,8 +55,7 @@ public static void deleteDatabase() {

@Test
public void test() {
DatabaseConfig.setConfigFile(false);
Database db = new Database();
Database db = new Database(true);
db.init();
List<Integer> i = new ArrayList<Integer>();
i.add(1);i.add(2);
Expand All @@ -75,7 +73,7 @@ public void test() {
//TODO: is this test needed?
@Test
public void persistFactoryGraph() {
Database db = new Database();
Database db = new Database(true);
db.init();
try {

Expand All @@ -85,8 +83,7 @@ public void persistFactoryGraph() {

@Test
public void persistGraphs() {
DatabaseConfig.setConfigFile(true);
Database db = new Database();
Database db = new Database(true);
db.deleteDatabase();
db.init();
CustomGraph g1 = getGraph1();
Expand All @@ -96,12 +93,11 @@ public void persistGraphs() {
System.out.println("start");
this.persistExampleGraphCoverCMap(g1);
this.persistExampleGraphCoverCMap(g2);
this.persistExampleGraphCoverCMap(g3);
this.persistExampleGraphCoverCMap(g4);
}

public void persistExampleGraphCoverCMap(CustomGraph g) {
Database db = new Database();
Database db = new Database(true);
db.init();

Cover c1 = getLOCCover(g);
Expand Down

0 comments on commit 59cc32e

Please sign in to comment.