Fixed test
This commit is contained in:
parent
b065d1136e
commit
267eda7afd
1 changed files with 14 additions and 15 deletions
|
|
@ -6,7 +6,6 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import se.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.hal.plugin.netscan.NetworkDevice;
|
|
||||||
import se.hal.util.UTCTimeUtility;
|
import se.hal.util.UTCTimeUtility;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.DBUpgradeHandler;
|
import zutil.db.DBUpgradeHandler;
|
||||||
|
|
@ -16,20 +15,20 @@ public class SensorDataAggregationDeamonTest {
|
||||||
private static final String DEFAULT_DB_FILE = "hal-default.db";
|
private static final String DEFAULT_DB_FILE = "hal-default.db";
|
||||||
|
|
||||||
private static DBConnection db;
|
private static DBConnection db;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setupDatabase() throws Exception{
|
public void setupDatabase() throws Exception{
|
||||||
System.out.println("-----------------------------------------------");
|
System.out.println("-----------------------------------------------");
|
||||||
|
|
||||||
//setup loggin
|
//setup loggin
|
||||||
System.out.println("Setting up logging");
|
System.out.println("Setting up logging");
|
||||||
LogUtil.readConfiguration("logging.properties");
|
LogUtil.readConfiguration("logging.properties");
|
||||||
|
|
||||||
//create in memory database
|
//create in memory database
|
||||||
System.out.println("Creating a in-memory databse for test");
|
System.out.println("Creating a in-memory databse for test");
|
||||||
db = new DBConnection(DBConnection.DBMS.SQLite, ":memory:");
|
db = new DBConnection(DBConnection.DBMS.SQLite, ":memory:");
|
||||||
HalContext.setDB(db);
|
HalContext.setDB(db);
|
||||||
|
|
||||||
//upgrade the database to latest version
|
//upgrade the database to latest version
|
||||||
System.out.println("Upgrading in-memory databse to latest version");
|
System.out.println("Upgrading in-memory databse to latest version");
|
||||||
DBConnection referenceDB = new DBConnection(DBConnection.DBMS.SQLite, DEFAULT_DB_FILE);
|
DBConnection referenceDB = new DBConnection(DBConnection.DBMS.SQLite, DEFAULT_DB_FILE);
|
||||||
|
|
@ -38,17 +37,17 @@ public class SensorDataAggregationDeamonTest {
|
||||||
handler.addIgnoredTable("sqlite_sequence"); //sqlite internal
|
handler.addIgnoredTable("sqlite_sequence"); //sqlite internal
|
||||||
handler.setTargetDB(db);
|
handler.setTargetDB(db);
|
||||||
handler.upgrade();
|
handler.upgrade();
|
||||||
|
|
||||||
//populate the database with data
|
//populate the database with data
|
||||||
System.out.println("Adding user to database");
|
System.out.println("Adding user to database");
|
||||||
db.exec("INSERT INTO user(id, external, username) VALUES(222, 0, 'test')"); //adding user
|
db.exec("INSERT INTO user(id, external, username) VALUES(222, 0, 'test')"); //adding user
|
||||||
System.out.println("Adding sensor to database");
|
System.out.println("Adding sensor to database");
|
||||||
db.exec("INSERT INTO sensor(id, user_id, external_id, type) VALUES(111, 222, 333, '"+NetworkDevice.class.getName()+"')"); //adding sensor
|
db.exec("INSERT INTO sensor(id, user_id, external_id, type) VALUES(111, 222, 333, 'se.hal.plugin.netscan.NetworkDevice')"); //adding sensor
|
||||||
System.out.println("Generating raw data and saving it to the database...");
|
System.out.println("Generating raw data and saving it to the database...");
|
||||||
PreparedStatement stmt = db.getPreparedStatement("INSERT INTO sensor_data_raw (timestamp, sensor_id, data) VALUES(?, ?, ?)");
|
PreparedStatement stmt = db.getPreparedStatement("INSERT INTO sensor_data_raw (timestamp, sensor_id, data) VALUES(?, ?, ?)");
|
||||||
try{
|
try{
|
||||||
db.getConnection().setAutoCommit(false);
|
db.getConnection().setAutoCommit(false);
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
for(int i = 0; i < 100000; ++i){
|
for(int i = 0; i < 100000; ++i){
|
||||||
stmt.setLong(1, startTime-(UTCTimeUtility.MINUTE_IN_MS*i));
|
stmt.setLong(1, startTime-(UTCTimeUtility.MINUTE_IN_MS*i));
|
||||||
|
|
@ -56,7 +55,7 @@ public class SensorDataAggregationDeamonTest {
|
||||||
stmt.setFloat(3, 7.323f);
|
stmt.setFloat(3, 7.323f);
|
||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
DBConnection.execBatch(stmt);
|
DBConnection.execBatch(stmt);
|
||||||
db.getConnection().commit();
|
db.getConnection().commit();
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|
@ -65,20 +64,20 @@ public class SensorDataAggregationDeamonTest {
|
||||||
}finally{
|
}finally{
|
||||||
db.getConnection().setAutoCommit(true);
|
db.getConnection().setAutoCommit(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Ready for test!");
|
System.out.println("Ready for test!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAggregation(){
|
public void testAggregation(){
|
||||||
System.out.println("Start testing raw data aggregation");
|
System.out.println("Start testing raw data aggregation");
|
||||||
SensorDataAggregatorDaemon aggrDeamon = new SensorDataAggregatorDaemon();
|
SensorDataAggregatorDaemon aggrDeamon = new SensorDataAggregatorDaemon();
|
||||||
aggrDeamon.run();
|
aggrDeamon.run();
|
||||||
|
|
||||||
//TODO: verify the aggregation
|
//TODO: verify the aggregation
|
||||||
|
|
||||||
System.out.println("Finished testing raw data aggregation");
|
System.out.println("Finished testing raw data aggregation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue