Search in sources :

Example 1 with FakeServer

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());
}
Also used : FakeServer(org.teiid.jdbc.FakeServer) InetSocketAddress(java.net.InetSocketAddress) SocketConfiguration(org.teiid.transport.SocketConfiguration) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) SSLConfiguration(org.teiid.transport.SSLConfiguration) SocketListener(org.teiid.transport.SocketListener) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ArrayList(java.util.ArrayList) List(java.util.List) QueryExpression(org.teiid.language.QueryExpression) BeforeClass(org.junit.BeforeClass)

Example 2 with FakeServer

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");
}
Also used : FakeServer(org.teiid.jdbc.FakeServer) Connection(java.sql.Connection) Logger(java.util.logging.Logger) Before(org.junit.Before)

Example 3 with FakeServer

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;
}
Also used : DummyTransactionManager(org.infinispan.transaction.tm.DummyTransactionManager) FakeServer(org.teiid.jdbc.FakeServer) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration)

Example 4 with FakeServer

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));
}
Also used : FakeServer(org.teiid.jdbc.FakeServer) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 5 with FakeServer

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));
}
Also used : FakeServer(org.teiid.jdbc.FakeServer) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

FakeServer (org.teiid.jdbc.FakeServer)23 BeforeClass (org.junit.BeforeClass)13 EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)8 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)5 Before (org.junit.Before)4 Test (org.junit.Test)4 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)4 InetSocketAddress (java.net.InetSocketAddress)3 Connection (java.sql.Connection)3 QueryExpression (org.teiid.language.QueryExpression)3 TranslatorException (org.teiid.translator.TranslatorException)3 ResultSet (java.sql.ResultSet)2 Properties (java.util.Properties)2 DummyTransactionManager (org.infinispan.transaction.tm.DummyTransactionManager)2 TeiidSQLException (org.teiid.jdbc.TeiidSQLException)2 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)2 ExecutionContext (org.teiid.translator.ExecutionContext)2 ResultSetExecution (org.teiid.translator.ResultSetExecution)2 IOException (java.io.IOException)1 NotSerializableException (java.io.NotSerializableException)1