use of org.knime.core.data.util.ObjectToDataCellConverter in project knime-core by knime.
the class DataContainerTest method testRestoreIntoMemory.
// testBigFile()
/**
* Restoring into main memory.
* @see ContainerTable#restoreIntoMemory()
*/
public void testRestoreIntoMemory() {
// with these setting (50, 100) it will write an 250MB cache file
// (the latest data this value was checked: 31. August 2006...)
final int colCount = 50;
final int rowCount = 100;
String[] names = new String[colCount];
DataType[] types = new DataType[colCount];
for (int c = 0; c < colCount; c++) {
names[c] = "Column " + c;
switch(c % 3) {
case 0:
types[c] = DoubleCell.TYPE;
break;
case 1:
types[c] = StringCell.TYPE;
break;
case 2:
types[c] = IntCell.TYPE;
break;
default:
throw new InternalError();
}
}
DataTableSpec spec = new DataTableSpec(names, types);
names = null;
types = null;
DataContainer container = new DataContainer(spec, true, 0);
final ObjectToDataCellConverter conv = new ObjectToDataCellConverter();
final long seed = System.currentTimeMillis();
Random rand = new Random(seed);
for (int i = 0; i < rowCount; i++) {
DataRow row = createRandomRow(i, colCount, rand, conv);
container.addRowToTable(row);
row = null;
}
container.close();
assertTrue(container.getBufferedTable().getBuffer().usesOutFile());
final Throwable[] throwables = new Throwable[1];
final ContainerTable table = container.getBufferedTable();
table.restoreIntoMemory();
// different iterators restore the content, each of which one row
RowIterator[] its = new RowIterator[10];
for (int i = 0; i < its.length; i++) {
its[i] = table.iterator();
for (int count = 0; count < i + 1; count++) {
its[i].next();
}
}
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
int i = 0;
Random rand1 = new Random(seed);
for (RowIterator it = table.iterator(); it.hasNext(); i++) {
DataRow row1 = createRandomRow(i, colCount, rand1, conv);
DataRow row2 = it.next();
assertEquals(row1, row2);
}
assertEquals(i, rowCount);
} catch (Throwable t) {
throwables[0] = t;
}
}
};
// Runnable
// make two threads read the buffer (file) concurrently.
Thread t1 = new Thread(runnable);
Thread t2 = new Thread(runnable);
t1.start();
t2.start();
try {
// seems that the event dispatch thread must not release the
// reference to the table, otherwise it is (I guess!!) garbage
// collected: You comment these lines and see the error message.
t1.join();
t2.join();
} catch (InterruptedException ie) {
ie.printStackTrace();
fail();
}
if (throwables[0] != null) {
throw new RuntimeException(throwables[0]);
}
}
use of org.knime.core.data.util.ObjectToDataCellConverter in project knime-core by knime.
the class DataContainerTest method testBigFile.
// testAddRowToTable()
/**
* Try a big file :-).
*/
public void testBigFile() {
// with these setting (50, 1000) it will write an 250MB cache file
// (the latest data this value was checked: 31. August 2006...)
final int colCount = 50;
final int rowCount = 100;
String[] names = new String[colCount];
DataType[] types = new DataType[colCount];
for (int c = 0; c < colCount; c++) {
names[c] = "Column " + c;
switch(c % 3) {
case 0:
types[c] = DoubleCell.TYPE;
break;
case 1:
types[c] = StringCell.TYPE;
break;
case 2:
types[c] = IntCell.TYPE;
break;
default:
throw new InternalError();
}
}
DataTableSpec spec = new DataTableSpec(names, types);
names = null;
types = null;
DataContainer container = new DataContainer(spec);
final ObjectToDataCellConverter conv = new ObjectToDataCellConverter();
final long seed = System.currentTimeMillis();
Random rand = new Random(seed);
for (int i = 0; i < rowCount; i++) {
DataRow row = createRandomRow(i, colCount, rand, conv);
container.addRowToTable(row);
}
container.close();
final Throwable[] throwables = new Throwable[1];
final DataTable table = container.getTable();
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
int i = 0;
Random rand1 = new Random(seed);
for (RowIterator it = table.iterator(); it.hasNext(); i++) {
DataRow row1 = createRandomRow(i, colCount, rand1, conv);
DataRow row2 = it.next();
assertEquals(row1, row2);
}
assertEquals(i, rowCount);
} catch (Throwable t) {
throwables[0] = t;
}
}
};
// Runnable
// make two threads read the buffer (file) concurrently.
Thread t1 = new Thread(runnable);
Thread t2 = new Thread(runnable);
t1.start();
t2.start();
try {
// seems that the event dispatch thread must not release the
// reference to the table, otherwise it is (I guess!!) garbage
// collected: You comment these lines and see the error message.
t1.join();
t2.join();
} catch (InterruptedException ie) {
ie.printStackTrace();
fail();
}
if (throwables[0] != null) {
throw new RuntimeException(throwables[0]);
}
}
Aggregations