Search in sources :

Example 6 with EmbeddedConfiguration

use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.

the class TestDDLMetadataStore method testVDBExport.

@Test
public void testVDBExport() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    ec.setUseDisk(false);
    ec.setSecurityHelper(new ThreadLocalSecurityHelper());
    es.addTranslator("y", new TestEmbeddedServer.FakeTranslator(false));
    es.start(ec);
    final AtomicInteger counter = new AtomicInteger();
    ConnectionFactoryProvider<AtomicInteger> cfp = new EmbeddedServer.SimpleConnectionFactoryProvider<AtomicInteger>(counter);
    es.addConnectionFactoryProvider("z", cfp);
    es.addMetadataRepository("myrepo", Mockito.mock(MetadataRepository.class));
    es.deployVDB(new FileInputStream(UnitTestUtil.getTestDataPath() + "/first-db.ddl"), true);
    Admin admin = es.getAdmin();
    VDBMetaData vdb = (VDBMetaData) admin.getVDB("empty", "2");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    VDBMetadataParser.marshell(vdb, out);
    String expected = ObjectConverterUtil.convertFileToString(new File(UnitTestUtil.getTestDataPath() + "/" + "first-vdb.xml"));
    assertEquals(expected, new String(out.toByteArray()));
    String exportedDdl = admin.getSchema("empty", "2", null, null, null);
    Assert.assertEquals(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("first-vdb.ddl")), exportedDdl);
}
Also used : TestEmbeddedServer(org.teiid.runtime.TestEmbeddedServer) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Admin(org.teiid.adminapi.Admin) FileInputStream(java.io.FileInputStream) MetadataRepository(org.teiid.metadata.MetadataRepository) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) File(java.io.File) Test(org.junit.Test)

Example 7 with EmbeddedConfiguration

use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.

the class TestDDLMetadataStore method testRoles.

@Test
public void testRoles() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    ec.setUseDisk(false);
    ec.setSecurityHelper(new ThreadLocalSecurityHelper());
    es.addTranslator("y", new TestEmbeddedServer.FakeTranslator(false));
    es.addTranslator("y2", new TestEmbeddedServer.FakeTranslator(false));
    final AtomicInteger counter = new AtomicInteger();
    ConnectionFactoryProvider<AtomicInteger> cfp = new EmbeddedServer.SimpleConnectionFactoryProvider<AtomicInteger>(counter);
    es.addConnectionFactoryProvider("z", cfp);
    es.start(ec);
    es.addMetadataRepository("myrepo", Mockito.mock(MetadataRepository.class));
    es.deployVDB(new FileInputStream(UnitTestUtil.getTestDataPath() + "/first-db.ddl"), true);
    TeiidDriver td = es.getDriver();
    Connection c = td.connect("jdbc:teiid:empty", null);
    Statement s = c.createStatement();
    ResultSet rs = s.executeQuery("select * from mytable");
    assertFalse(rs.next());
    assertEquals("my-column", rs.getMetaData().getColumnLabel(1));
    s.execute("update mytable set \"my-column\" = 'a'");
    assertEquals(2, s.getUpdateCount());
    try {
        s.execute("delete from mytable where \"my-column\" = 'a'");
        fail("should have stopped by roles");
    } catch (Exception e) {
    // pass
    }
}
Also used : TestEmbeddedServer(org.teiid.runtime.TestEmbeddedServer) Statement(java.sql.Statement) Connection(java.sql.Connection) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) FileInputStream(java.io.FileInputStream) LoginException(javax.security.auth.login.LoginException) AdminProcessingException(org.teiid.adminapi.AdminProcessingException) AdminException(org.teiid.adminapi.AdminException) MetadataRepository(org.teiid.metadata.MetadataRepository) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSet(java.sql.ResultSet) TeiidDriver(org.teiid.jdbc.TeiidDriver) Test(org.junit.Test)

Example 8 with EmbeddedConfiguration

use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.

the class TestDDLMetadataStore method testMultiSource.

@Test
public void testMultiSource() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    ec.setUseDisk(false);
    es.start(ec);
    es.addTranslator(FileExecutionFactory.class);
    es.deployVDB(new FileInputStream(UnitTestUtil.getTestDataPath() + "/" + "multisource-vdb.ddl"), true);
    es.getAdmin().addSource("multisource", "1", "MarketData", "x", "file", "z");
    Connection c = es.getDriver().connect("jdbc:teiid:multisource", null);
    DatabaseMetaData dmd = c.getMetaData();
    ResultSet rs = dmd.getProcedureColumns(null, null, "deleteFile", null);
    int count = 0;
    while (rs.next()) {
        count++;
    }
    assertEquals(2, count);
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) DatabaseMetaData(java.sql.DatabaseMetaData) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 9 with EmbeddedConfiguration

use of org.teiid.runtime.EmbeddedConfiguration 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 10 with EmbeddedConfiguration

use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.

the class TestMaterializationPerformance method setup.

@Before
public void setup() {
    es = new EmbeddedServer();
    es.start(new EmbeddedConfiguration());
}
Also used : EmbeddedServer(org.teiid.runtime.EmbeddedServer) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) Before(org.junit.Before)

Aggregations

EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)26 Test (org.junit.Test)12 Connection (java.sql.Connection)9 BeforeClass (org.junit.BeforeClass)8 FakeServer (org.teiid.jdbc.FakeServer)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 ResultSet (java.sql.ResultSet)6 EmbeddedServer (org.teiid.runtime.EmbeddedServer)6 Statement (java.sql.Statement)5 InetSocketAddress (java.net.InetSocketAddress)4 DummyTransactionManager (org.infinispan.transaction.tm.DummyTransactionManager)3 Before (org.junit.Before)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)3 File (java.io.File)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Subject (javax.security.auth.Subject)2