/*
* 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
*/
/*
*/
/**
* Unit tests for {@code JDBCHistoryCache}.
*/
"org.apache.derby.jdbc.EmbeddedDriver";
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)");
}
}
/**
* 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 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.
*/
// test get history for single file
// test get history for directory
// test incremental update
"3:78649c3ec6cb",
true);
// test clearing of cache
assertTrue("History should be empty",
}
/**
* Test that {@code getLatestCachedRevision()} returns the correct
* revision.
*/
assertTrue("Unexpected order of history entries",
assertEquals("Incorrect latest revision",
// test incremental update
}
/**
* Test that {@code hasCacheForDirectory()} works.
*/
// 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.
// Bug #19230: Test that it works for sub-directories too, not only
// for the repository root.
// Also test that we don't claim to have history for a directory
// that's not under version control, even if it lives in a version
// controlled source tree.
}
/**
* Test that get() is able to continue and return successfully after a lock
* timeout when accessing the database.
*/
// 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.
*/
"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",
}
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.
*/
// Create an entry where author is null
HistoryEntry e = new HistoryEntry(
}
}