Search in sources :

Example 1 with XmlDataSet

use of org.dbunit.dataset.xml.XmlDataSet in project SSM by Intel-bigdata.

the class TestDBAdapter method testGetFileIds.

@Test
public void testGetFileIds() throws Exception {
    createTables(databaseTester.getConnection());
    IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("files.xml"));
    databaseTester.setDataSet(dataSet);
    databaseTester.onSetup();
    DBAdapter dbAdapter = new DBAdapter(databaseTester.getConnection().getConnection());
    List<String> paths = Arrays.asList("file1", "file2", "file3");
    Map<String, Long> pathToID = dbAdapter.getFileIDs(paths);
    Assert.assertTrue(pathToID.get("file1") == 101);
    Assert.assertTrue(pathToID.get("file2") == 102);
    Assert.assertTrue(pathToID.get("file3") == 103);
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) IDataSet(org.dbunit.dataset.IDataSet) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) Test(org.junit.Test)

Example 2 with XmlDataSet

use of org.dbunit.dataset.xml.XmlDataSet in project SSM by Intel-bigdata.

the class TestDBAdapter method testCreateProportionView.

@Test
public void testCreateProportionView() throws Exception {
    Statement statement = databaseTester.getConnection().getConnection().createStatement();
    statement.execute(AccessCountTable.createTableSQL("table1"));
    statement.execute(AccessCountTable.createTableSQL("table2"));
    statement.execute(AccessCountTable.createTableSQL("table3"));
    statement.execute(AccessCountTable.createTableSQL("expect"));
    IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("accessCountTable.xml"));
    databaseTester.setDataSet(dataSet);
    databaseTester.onSetup();
    AccessCountTable table3 = new AccessCountTable("table3", 0L, 10L, TimeGranularity.SECOND);
    DBAdapter dbAdapter = new DBAdapter(databaseTester.getConnection().getConnection());
    // 50%
    AccessCountTable viewTable = new AccessCountTable(0L, 5L);
    dbAdapter.createProportionView(viewTable, table3);
    ITable actual = databaseTester.getConnection().createTable(viewTable.getTableName());
    ITable expect = databaseTester.getConnection().createTable(table3.getTableName());
    SortedTable sortedActual = new SortedTable(actual, new String[] { "fid" });
    sortedActual.setUseComparable(true);
    Assert.assertTrue(sortedActual.getRowCount() == expect.getRowCount());
    for (int i = 0; i < expect.getRowCount(); i++) {
        Integer actualAC = (Integer) sortedActual.getValue(i, AccessCountTable.ACCESSCOUNT_FIELD);
        Integer expectAC = (Integer) expect.getValue(i, AccessCountTable.ACCESSCOUNT_FIELD);
        Assert.assertTrue(actualAC == expectAC / 2);
    }
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) Statement(java.sql.Statement) SortedTable(org.dbunit.dataset.SortedTable) ITable(org.dbunit.dataset.ITable) IDataSet(org.dbunit.dataset.IDataSet) AccessCountTable(org.smartdata.server.metastore.tables.AccessCountTable) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) Test(org.junit.Test)

Example 3 with XmlDataSet

use of org.dbunit.dataset.xml.XmlDataSet in project SSM by Intel-bigdata.

the class TestAccessCountTableManager method testAddAccessCountInfo.

@Test
public void testAddAccessCountInfo() throws Exception {
    createTables(databaseTester.getConnection());
    IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("files.xml"));
    databaseTester.setDataSet(dataSet);
    databaseTester.onSetup();
    DBAdapter adapter = new DBAdapter(databaseTester.getConnection().getConnection());
    AccessCountTableManager manager = new AccessCountTableManager(adapter);
    List<FileAccessEvent> accessEvents = new ArrayList<>();
    accessEvents.add(new FileAccessEvent("file1", 0));
    accessEvents.add(new FileAccessEvent("file2", 1));
    accessEvents.add(new FileAccessEvent("file2", 2));
    accessEvents.add(new FileAccessEvent("file3", 2));
    accessEvents.add(new FileAccessEvent("file3", 3));
    accessEvents.add(new FileAccessEvent("file3", 4));
    accessEvents.add(new FileAccessEvent("file3", 5000));
    manager.onAccessEventsArrived(accessEvents);
    AccessCountTable accessCountTable = new AccessCountTable(0L, 5000L);
    ITable actual = databaseTester.getConnection().createTable(accessCountTable.getTableName());
    ITable expect = databaseTester.getDataSet().getTable("expect1");
    SortedTable sortedActual = new SortedTable(actual, new String[] { "fid" });
    sortedActual.setUseComparable(true);
    Assertion.assertEquals(expect, sortedActual);
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) SortedTable(org.dbunit.dataset.SortedTable) ArrayList(java.util.ArrayList) ITable(org.dbunit.dataset.ITable) IDataSet(org.dbunit.dataset.IDataSet) FileAccessEvent(org.smartdata.metrics.FileAccessEvent) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) Test(org.junit.Test) DBTest(org.smartdata.server.metastore.DBTest)

Example 4 with XmlDataSet

use of org.dbunit.dataset.xml.XmlDataSet in project SSM by Intel-bigdata.

the class TestTableAggregator method testAggregate.

@Test
public void testAggregate() throws Exception {
    AccessCountTableAggregator aggregator = new AccessCountTableAggregator(null);
    createTables(databaseTester.getConnection());
    IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("accessCountTable.xml"));
    databaseTester.setDataSet(dataSet);
    databaseTester.onSetup();
    AccessCountTable result = new AccessCountTable("actual", 0L, 0L, TimeGranularity.MINUTE);
    AccessCountTable table1 = new AccessCountTable("table1", 0L, 0L, TimeGranularity.SECOND);
    AccessCountTable table2 = new AccessCountTable("table2", 0L, 0L, TimeGranularity.SECOND);
    AccessCountTable table3 = new AccessCountTable("table3", 0L, 0L, TimeGranularity.SECOND);
    String aggregateStatement = aggregator.aggregateSQLStatement(result, Lists.newArrayList(table1, table2, table3));
    Statement statement = databaseTester.getConnection().getConnection().createStatement();
    statement.execute(aggregateStatement);
    statement.close();
    ITable actual = databaseTester.getConnection().createTable(result.getTableName());
    ITable expect = databaseTester.getDataSet().getTable("expect");
    Assertion.assertEquals(expect, actual);
}
Also used : Statement(java.sql.Statement) ITable(org.dbunit.dataset.ITable) IDataSet(org.dbunit.dataset.IDataSet) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) Test(org.junit.Test) DBTest(org.smartdata.server.metastore.DBTest)

Example 5 with XmlDataSet

use of org.dbunit.dataset.xml.XmlDataSet in project SSM by Intel-bigdata.

the class TestTableAggregator method testAggregate.

@Test
public void testAggregate() throws Exception {
    createTables(databaseTester.getConnection());
    IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("accessCountTable.xml"));
    databaseTester.setDataSet(dataSet);
    databaseTester.onSetup();
    MetaStore metaStore = new MetaStore(druidPool);
    prepareFiles(metaStore);
    AccessCountTable result = new AccessCountTable("actual", 0L, 0L, false);
    AccessCountTable table1 = new AccessCountTable("table1", 0L, 0L, false);
    AccessCountTable table2 = new AccessCountTable("table2", 0L, 0L, false);
    AccessCountTable table3 = new AccessCountTable("table3", 0L, 0L, false);
    metaStore.aggregateTables(result, Lists.newArrayList(table1, table2, table3));
    ITable actual = databaseTester.getConnection().createTable(result.getTableName());
    ITable expect = databaseTester.getDataSet().getTable("expect");
    Assertion.assertEquals(expect, actual);
}
Also used : MetaStore(org.smartdata.metastore.MetaStore) ITable(org.dbunit.dataset.ITable) IDataSet(org.dbunit.dataset.IDataSet) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) DBTest(org.smartdata.metastore.DBTest) Test(org.junit.Test)

Aggregations

IDataSet (org.dbunit.dataset.IDataSet)8 XmlDataSet (org.dbunit.dataset.xml.XmlDataSet)8 Test (org.junit.Test)6 ITable (org.dbunit.dataset.ITable)4 MetaStore (org.smartdata.metastore.MetaStore)3 DBAdapter (org.smartdata.server.metastore.DBAdapter)3 Statement (java.sql.Statement)2 SortedTable (org.dbunit.dataset.SortedTable)2 DBTest (org.smartdata.metastore.DBTest)2 DBTest (org.smartdata.server.metastore.DBTest)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)1 FileAccessEvent (org.smartdata.metrics.FileAccessEvent)1 FileAccessInfo (org.smartdata.model.FileAccessInfo)1 AccessCountTable (org.smartdata.server.metastore.tables.AccessCountTable)1