/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
* Unit tests for {@code JDBCHistoryCache}.
*/
"org.apache.derby.jdbc.EmbeddedDriver";
@SuppressWarnings("javadoc")
super(name);
}
/**
* Create a suite of tests to run. If the Derby classes are not present,
* skip this test.
*
* @return tests to run
*/
try {
return new TestSuite(JDBCHistoryCacheTest.class);
} catch (ClassNotFoundException e) {
return new TestSuite("JDBCHistoryCacheTest - empty (no derby.jar)");
}
}
@SuppressWarnings("unused")
try {
if (f.exists()) {
f.delete();
}
} catch (ClassNotFoundException e) {
// do nothing
} catch (SecurityException e) {
// ignore
} catch (NoSuchMethodException e) {
// ignore
} catch (IllegalArgumentException e) {
// ignore
} catch (IllegalAccessException e) {
// ignore
} catch (InvocationTargetException e) {
// ignore
}
}
try {
"S.SCHEMANAME FROM SYS.SYSTABLES T, SYS.SYSSCHEMAS S " +
"WHERE T.TABLETYPE = 'T' AND T.SCHEMAID = S.SCHEMAID");
}
}
+ "(?,?,?,?,?,?)");
if (f.exists()) {
f.delete();
}
}
} catch (SQLException e) {
} finally {
try {
} catch (SQLException e) {
// ignore
}
try {
} catch (SQLException e) {
// ignore
}
try {
} catch (SQLException e) {
// ignore
}
}
}
/**
* Set up the test environment with repositories and a cache instance.
*/
repositories = new TestRepository();
cache = new JDBCHistoryCache(
cache.initialize();
}
/**
* Clean up after the test. Remove the test repositories and shut down
* the database.
*/
repositories = null;
try {
} catch (SQLException sqle) {
// Expect SQLException with SQLState 08006 on successful shutdown
throw sqle;
}
}
}
/**
* Create a database URL to use for this test. The URL points to an
* in-memory Derby database.
*
* @return a database URL
*/
return "jdbc:derby:memory:DB-" + getName();
}
/**
* Import a new changeset into a Mercurial repository.
*
* @param reposRoot the root of the repository
* @param changesetFile file that contains the changeset to import
*/
};
if (exitCode != 0) {
fail("hg import failed." +
"\nexit code: " + exitCode +
}
}
/**
* Assert that two HistoryEntry objects are equal.
* @param expected the expected entry
* @param actual the actual entry
* @throws AssertFailure if the two entries don't match
*/
private static void assertSameEntries(
}
}
/**
* Assert that two lists of HistoryEntry objects are equal.
* @param expected the expected list of entries
* @param actual the actual list of entries
* @throws AssertFailure if the two lists don't match
*/
}
/**
* Basic tests for the {@code store()} and {@code get()} methods.
* @throws Exception
*/
@SuppressWarnings("boxing")
// test get history for single file
assertTrue("entry set should be empty",
// test get history for directory
assertTrue("entry set should be empty" ,
// test incremental update
if (RuntimeEnvironment.isOldJVM()) {
time *= 60;
}
"xyz", "Return failure when executed with no arguments", true);
// isDir = {null, true, false}
//dumpDB("0pre");
//dumpDB("0post");
// null == auto -> test for physical path -> fails -> assumes path is file
// force to take as file (same results as for null)
// force to take as dir
// test clearing of cache
assertTrue("History should be empty",
}
/**
* Test that {@code getLatestCachedRevision()} returns the correct
* revision.
* @throws Exception
*/
assertTrue("Unexpected order of history entries",
assertEquals("Incorrect latest revision",
// test incremental update
}
/**
* Test that {@code hasCacheForDirectory()} works.
* @throws Exception
*/
// Use a Mercurial repository and a Subversion repository in this test.
// None of the repositories should have any history.
// Store empty history, so still expect false.
// Store history for Mercurial repository.
// Store history for Subversion repository.
//dumpDB("pre");
//dumpDB("post");
// w/o mercurial repo fix there is a /mercurial subdir, but no /svn subdir
// w/ mercurial repo fix there is still no subdir
}
/**
* Test that get() is able to continue and return successfully after a lock
* timeout when accessing the database.
* @throws Exception
*/
// Set the lock timeout to one second to make it go faster.
Statement s = c.createStatement();
s.execute("call syscs_util.syscs_set_database_property" +
"('derby.locks.waitTimeout', '1')");
// Lock one of the tables exclusively in order to block get().
c.setAutoCommit(false);
// Originally, we locked the FILECHANGES table here, but that triggered
// a Derby bug (https://issues.apache.org/jira/browse/DERBY-4330), so
// now we lock the AUTHORS table instead.
s.execute("lock table opengrok.authors in exclusive mode");
s.close();
// Roll back the transaction in 1.5 seconds so that get() is able to
// continue after the first timeout.
public void run() {
try {
c.rollback();
c.close();
} catch (Exception e) {
ex[0] = e;
}
}
};
t.start();
// get() should be able to continue after a timeout.
t.join();
// Expose any exception thrown in the helper thread.
throw ex[0];
}
}
/**
* Regression test for bug #11663. If the commit message was longer than
* the maximum VARCHAR length, a truncation error would be raised by the
* database. Now the message should be truncated if such a message is
* encountered.
* @throws Exception
*/
"this is a line with 48 chars, including newline");
}
// Used to get a truncation error from the database here.
assertFalse("Long message should be truncated",
assertEquals("Start of message should be equal to original",
}
@SuppressWarnings("javadoc")
public void testGetInfo() {
assertTrue("Info should contain name of history cache",
assertTrue("Info should contain driver class",
}
/**
* Test that it is possible to store an entry with no author.
* Bug #11662.
* @throws Exception
*/
// Create an entry where author is null
HistoryEntry e = new HistoryEntry(
}
}