Okay I managed to reproduce it through a simple test, but I didn't
find away of catching the warning messaged and then failing the unit
test.
So the only way I know it failed is because I log warning messaged
from H2.
Thanks
br
Flemming
package com.performancetest.h2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Arrays;
import junit.framework.TestCase;
public class TestH2CachePerformance extends TestCase {
private static final int NO_OF_RECORDS = 100000;
static String URL = "jdbc:h2:/tmp/
testcache;CACHE_TYPE=SOFT_LRU;DB_CLOSE_DELAY=0;CACHE_SIZE=2500;TRACE_LEVEL_FILE=4"; //
$NON-NLS-1$
private Connection connection;
protected void setUp() throws Exception {
connection = DriverManager.getConnection(URL, "sa", ""); //
$NON-NLS-1$ //$NON-NLS-2$
connection.setAutoCommit(false);
Statement createStatement = connection.createStatement();
try {
createStatement.execute("drop table
TestH2CachePerformance;"); //$NON-NLS-1$
} catch (Exception e) {
// Expect it in case of the table does not exits
}
createStatement
.execute("create table TestH2CachePerformance (\"id\" INT,
\"FirstName\" CHAR(255),\"LastName\" CHAR(255));"); //$NON-NLS-1$
createStatement.close();
connection.commit();
}
public void testCache() throws Exception {
Statement insertStatement = connection.createStatement();
char[] firstCol = new char[255];
char[] secondCol = new char[255];
Arrays.fill(firstCol, 'A');
Arrays.fill(secondCol, 'B');
for (int i = 0; i < NO_OF_RECORDS; i++) {
insertStatement.addBatch("INSERT INTO
TestH2CachePerformance VALUES ("+i+", '"+new String(firstCol)
+"','"+new String(secondCol)+"');"); //$NON-NLS-1$ //$NON-NLS-2$ //
$NON-NLS-3$ //$NON-NLS-4$
}
int[] executeBatch = insertStatement.executeBatch();
insertStatement.close();
connection.commit();
}
protected void tearDown() throws Exception {
connection.close();
}
On Dec 12, 9:33 am, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:
Thanks for the test case! I could reproduce the problem. It occurs
when the cache size is smaller than the transaction, which is the case
in the test case you sent. H2 doesn't support very large transactions
that well currently, one of the top feature requests on the roadmap is
"Support large inserts and updates". I'm not sure however when I will
have time to implement it (it will probably be only available when
using the the page store, version 1.2.x).
As a workaround, I suggest to split large transactions into smaller
ones, or use a larger cache size.
I create a new issue
http://code.google.com/p/h2database/issues/detail?id=157 with a
simpler test case.
Regards,
Thomas