use of org.pentaho.di.www.SlaveSequence in project pentaho-kettle by pentaho.
the class SlaveSequenceIT method testSlaveSequenceRetrieval_AutoCreation.
/**
* This test retrieves next values from a slave sequence.<br>
*/
public void testSlaveSequenceRetrieval_AutoCreation() throws Exception {
init();
String SLAVE_SEQUENCE_NAME = "test";
SlaveServerConfig slaveConfig = new SlaveServerConfig("localhost", 8282, false);
slaveConfig.getSlaveServer().setUsername("cluster");
slaveConfig.getSlaveServer().setPassword("cluster");
String dbDir = System.getProperty("java.io.tmpdir") + "/" + UUID.randomUUID().toString() + "-slaveSeqTest-H2-DB";
DatabaseMeta databaseMeta = new DatabaseMeta("H2", "H2", "Native", null, dbDir, null, null, null);
slaveConfig.getDatabases().add(databaseMeta);
String table = "SLAVE_SEQUENCE";
String nameField = "SEQ_NAME";
String valueField = "SEQ_VALUE";
SlaveSequence slaveSequence = new SlaveSequence(SLAVE_SEQUENCE_NAME, 1L, databaseMeta, null, table, nameField, valueField);
slaveConfig.setAutomaticCreationAllowed(true);
slaveConfig.setAutoSequence(slaveSequence);
Database db = new Database(loggingObject, databaseMeta);
db.connect();
db.execStatement("CREATE TABLE SLAVE_SEQUENCE(SEQ_NAME VARCHAR(100), SEQ_VALUE INTEGER);");
db.disconnect();
// Start the Carte launcher
CarteLauncher carteLauncher = new CarteLauncher(slaveConfig);
Thread thread = new Thread(carteLauncher);
thread.start();
//
while (carteLauncher.getCarte() == null && !carteLauncher.isFailure()) {
Thread.sleep(100);
}
try {
long value = slaveConfig.getSlaveServer().getNextSlaveSequenceValue(SLAVE_SEQUENCE_NAME, 1000);
assertEquals(1L, value);
value = slaveConfig.getSlaveServer().getNextSlaveSequenceValue(SLAVE_SEQUENCE_NAME, 1000);
assertEquals(1001L, value);
value = slaveConfig.getSlaveServer().getNextSlaveSequenceValue("new sequence", 1000);
assertEquals(1L, value);
value = slaveConfig.getSlaveServer().getNextSlaveSequenceValue("new sequence", 1000);
assertEquals(1001L, value);
value = slaveConfig.getSlaveServer().getNextSlaveSequenceValue(SLAVE_SEQUENCE_NAME, 1000);
assertEquals(2001L, value);
} catch (Exception e) {
fail("And error was thrown for retrieval of an unknown sequence, auto-creation expected");
}
// After the test, stop the server
//
carteLauncher.getCarte().getWebServer().stopServer();
// Remove the database + table in the temporary directory
//
File dir = new File(dbDir);
if (dir.exists()) {
for (File child : dir.listFiles()) {
if (child.isFile()) {
child.delete();
}
}
dir.delete();
}
}
use of org.pentaho.di.www.SlaveSequence in project pentaho-kettle by pentaho.
the class SlaveSequenceIT method testSlaveSequenceRetrieval_Specifed.
/**
* This test retrieves next values from a slave sequence.<br>
*/
public void testSlaveSequenceRetrieval_Specifed() throws Exception {
init();
String SLAVE_SEQUENCE_NAME = "test";
SlaveServerConfig slaveConfig = new SlaveServerConfig("localhost", 8282, false);
slaveConfig.getSlaveServer().setUsername("cluster");
slaveConfig.getSlaveServer().setPassword("cluster");
String dbDir = System.getProperty("java.io.tmpdir") + "/" + UUID.randomUUID().toString() + "-slaveSeqTest-H2-DB";
DatabaseMeta databaseMeta = new DatabaseMeta("H2", "H2", "Native", null, dbDir, null, null, null);
slaveConfig.getDatabases().add(databaseMeta);
String table = "SLAVE_SEQUENCE";
String nameField = "SEQ_NAME";
String valueField = "SEQ_VALUE";
SlaveSequence slaveSequence = new SlaveSequence(SLAVE_SEQUENCE_NAME, 1L, databaseMeta, null, table, nameField, valueField);
slaveConfig.getSlaveSequences().add(slaveSequence);
Database db = new Database(loggingObject, databaseMeta);
db.connect();
db.execStatement("CREATE TABLE SLAVE_SEQUENCE(SEQ_NAME VARCHAR(100), SEQ_VALUE INTEGER);");
db.disconnect();
// Start the Carte launcher
CarteLauncher carteLauncher = new CarteLauncher(slaveConfig);
Thread thread = new Thread(carteLauncher);
thread.start();
//
while (carteLauncher.getCarte() == null && !carteLauncher.isFailure()) {
Thread.sleep(100);
}
long value = slaveConfig.getSlaveServer().getNextSlaveSequenceValue(SLAVE_SEQUENCE_NAME, 1000);
assertEquals(1L, value);
value = slaveConfig.getSlaveServer().getNextSlaveSequenceValue(SLAVE_SEQUENCE_NAME, 1000);
assertEquals(1001L, value);
try {
slaveConfig.getSlaveServer().getNextSlaveSequenceValue("Unknown sequence", 1000);
fail("No error was thrown for retrieval of an unknown sequence");
} catch (Exception e) {
// OK!
}
// After the test, stop the server
//
carteLauncher.getCarte().getWebServer().stopServer();
// Remove the database + table in the temporary directory
//
File dir = new File(dbDir);
if (dir.exists()) {
for (File child : dir.listFiles()) {
if (child.isFile()) {
child.delete();
}
}
dir.delete();
}
}
Aggregations