use of org.teiid.jdbc.FakeServer in project teiid by teiid.
the class TestJDBCSocketPerformance method oneTimeSetup.
@BeforeClass
public static void oneTimeSetup() throws Exception {
SocketConfiguration config = new SocketConfiguration();
config.setSSLConfiguration(new SSLConfiguration());
addr = new InetSocketAddress(0);
config.setBindAddress(addr.getHostName());
config.setPortNumber(0);
EmbeddedConfiguration dqpConfig = new EmbeddedConfiguration();
dqpConfig.setMaxActivePlans(2);
server = new FakeServer(false);
server.start(dqpConfig);
ModelMetaData mmd = new ModelMetaData();
mmd.setName("x");
mmd.setModelType(Type.PHYSICAL);
mmd.addSourceMapping("x", "hc", null);
mmd.setSchemaSourceType("ddl");
StringBuffer ddl = new StringBuffer("create foreign table x (col0 string");
for (int i = 1; i < 10; i++) {
ddl.append(",").append(" col").append(i).append(" string");
}
ddl.append(");");
mmd.setSchemaText(ddl.toString());
server.addTranslator("hc", new HardCodedExecutionFactory() {
@Override
protected List<? extends List<?>> getData(QueryExpression command) {
List<List<String>> result = new ArrayList<List<String>>();
int size = command.getProjectedQuery().getDerivedColumns().size();
for (int i = 0; i < 64; i++) {
List<String> row = new ArrayList<String>(size);
for (int j = 0; j < size; j++) {
row.add("abcdefghi" + j);
}
result.add(row);
}
return result;
}
});
server.deployVDB("x", mmd);
jdbcTransport = new SocketListener(addr, config, server.getClientServiceRegistry(), BufferManagerFactory.getStandaloneBufferManager());
}
use of org.teiid.jdbc.FakeServer in project teiid by teiid.
the class TestExternalMatViews method setUp.
@Before
public void setUp() throws Exception {
server = new FakeServer(true);
if (DEBUG)
LogManager.setLogListener(new org.teiid.logging.Logger() {
@Override
public void shutdown() {
}
@Override
public void removeMdc(String key) {
}
@Override
public void putMdc(String key, String val) {
}
@Override
public void log(int level, String context, Throwable t, Object... msg) {
StringBuilder sb = new StringBuilder();
for (Object str : msg) {
sb.append(str.toString());
}
System.out.println(sb.toString());
}
@Override
public void log(int level, String context, Object... msg) {
StringBuilder sb = new StringBuilder();
for (Object str : msg) {
sb.append(str.toString());
}
System.out.println(sb.toString());
}
@Override
public boolean isEnabled(String context, int msgLevel) {
return msgLevel <= 4;
}
});
Connection c = h2DataSource.getConnection();
c.createStatement().execute("delete from status");
c.createStatement().execute("delete from mat_v1");
c.createStatement().execute("delete from mat_v1_stage");
c.createStatement().execute("delete from mat_v2");
}
use of org.teiid.jdbc.FakeServer in project teiid by teiid.
the class TestExternalMatViews method createServer.
private FakeServer createServer(String nodeName, String ispn, String jgroups) throws Exception {
FakeServer server = new FakeServer(false);
EmbeddedConfiguration config = new EmbeddedConfiguration();
config.setInfinispanConfigFile(ispn);
config.setJgroupsConfigFile(jgroups);
config.setNodeName(nodeName);
config.setTransactionManager(new DummyTransactionManager());
server.start(config, true);
return server;
}
use of org.teiid.jdbc.FakeServer in project teiid by teiid.
the class TestExternalMatViews method testNodeFailure.
@Test
public void testNodeFailure() throws Exception {
FakeServer server1 = createServer("server1", "infinispan-replicated-config.xml", "tcp-shared.xml");
HardCodedExecutionFactory hcef = setupData(server1);
ModelMetaData sourceModel = setupSourceModel();
ModelMetaData matViewModel = setupMatViewModel();
ModelMetaData viewModel = new ModelMetaData();
viewModel.setName("view1");
viewModel.setModelType(Type.VIRTUAL);
viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:MATVIEW_TTL\" 30000, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_SHARE_SCOPE\" 'FULL', " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
server1.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(1000);
FakeServer server2 = createServer("server2", "infinispan-replicated-config-1.xml", "tcp-shared.xml");
setupData(server2);
server2.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(5000);
Connection c = h2DataSource.getConnection();
ResultSet rs = c.createStatement().executeQuery("SELECT LoadState, Nodename FROM Status WHERE VDBName = 'comp'");
rs.next();
assertEquals("LOADED", rs.getString(1));
assertEquals("server1", rs.getString(2));
int update = c.createStatement().executeUpdate("UPDATE Status SET LoadState = 'LOADING' WHERE VDBName = 'comp' AND Nodename = 'server1'");
assertEquals(1, update);
server1.stop();
Thread.sleep(1000);
rs = c.createStatement().executeQuery("SELECT LoadState, Nodename FROM Status WHERE VDBName = 'comp'");
rs.next();
assertEquals("LOADED", rs.getString(1));
assertEquals("server2", rs.getString(2));
}
use of org.teiid.jdbc.FakeServer in project teiid by teiid.
the class TestExternalMatViews method testRestartServerInMiddleOfLoading.
@Test
public void testRestartServerInMiddleOfLoading() throws Exception {
HardCodedExecutionFactory hcef = setupData(server);
ModelMetaData sourceModel = setupSourceModel();
ModelMetaData matViewModel = setupMatViewModel();
ModelMetaData viewModel = new ModelMetaData();
viewModel.setName("view1");
viewModel.setModelType(Type.VIRTUAL);
viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:MATVIEW_TTL\" 3000, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
server.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(1000);
// test that the matview loaded
conn = server.createConnection("jdbc:teiid:comp");
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("select * from view1.v1 order by col");
rs.next();
assertEquals(1, rs.getInt(1));
assertEquals("town", rs.getString(2));
// now change the status table underneath
h2DataSource = getDatasource();
Connection c = h2DataSource.getConnection();
assertNotNull(c);
Statement stmt = c.createStatement();
boolean update = stmt.execute("UPDATE status SET LOADSTATE = 'LOADING' WHERE NAME = 'v1'");
// this is update
assertFalse(update);
assertEquals(1, stmt.getUpdateCount());
rs = c.createStatement().executeQuery("SELECT LOADSTATE, NODENAME FROM status");
assertTrue(rs.next());
assertEquals("LOADING", rs.getString(1));
assertEquals("localhost", rs.getString(2));
server.stop();
server = new FakeServer(true);
setupData(server);
setupSourceModel();
setupMatViewModel();
server.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(1000);
rs = c.createStatement().executeQuery("SELECT LOADSTATE, NODENAME FROM STATUS WHERE NAME = 'v1'");
assertTrue(rs.next());
assertEquals("LOADED", rs.getString(1));
assertEquals("localhost", rs.getString(2));
}
Aggregations