Skip to content

Commit

Permalink
Unit tests for the rewritten functionality of RuntimeLogger.
Browse files Browse the repository at this point in the history
  • Loading branch information
iridin committed Feb 17, 2015
1 parent 59711fd commit e76f36f
Show file tree
Hide file tree
Showing 3 changed files with 448 additions and 21 deletions.
9 changes: 7 additions & 2 deletions jdeeco-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.3.04</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down Expand Up @@ -94,7 +99,7 @@
</dependency>
</dependencies>
<distributionManagement>
<repository>
<repository>
<id>d3s</id>
<name>D3S maven repository</name>
<url>https://gitlab.d3s.mff.cuni.cz:8443/nexus/content/repositories/releases</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,23 @@ public void init(CurrentTimeProvider currentTimeProvider,
* for the logging.
* @throws IllegalStateException Thrown if the {@link RuntimeLogger#init} method hasn't
* been called before this method is being called.
* @throws IllegalArgumentException Thrown if the given argument is null.
* @throws IllegalArgumentException Thrown if the given argument is null. Or if the <em>record</em>
* returns null when the {@link RuntimeLogRecord#getId()} or the {@link RuntimeLogRecord#getValues()}
* method is called.
*/
public void log(RuntimeLogRecord record) // TODO: check whether the record fields are not null
public void log(RuntimeLogRecord record)
throws IOException, IllegalStateException {
if (timeProvider == null)
throw new IllegalStateException(
"The SimLogger class not initialized.");
if (record == null)
throw new IllegalArgumentException(String.format(
"The argument \"%s\" is null.", "record"));
if(record.getId() == null) throw new IllegalArgumentException(String.format(
"The %s method invoked on the %s argument returns null.", "getID()", "record"));
if(record.getValues() == null) throw new IllegalArgumentException(String.format(
"The %s method invoked on the %s argument returns null.", "getValues()", "record"));


StringBuilder recordBuilder = new StringBuilder();
long dataOffset = currentDataOffset;
Expand Down Expand Up @@ -361,7 +368,7 @@ public void log(RuntimeLogRecord record) // TODO: check whether the record field

// If a snapshot is being logged and there passed enough time since the last index was written
if (snapshotTypes.contains(record.getClass())
&& currentTime - lastIndexTime > INDEX_MIN_PERIOD) {
&& currentTime - lastIndexTime >= INDEX_MIN_PERIOD) {
logIndex(currentTime, dataOffset);
}
} catch (IOException e) {
Expand Down Expand Up @@ -413,10 +420,17 @@ private void logIndex(long currentTime, long dataOffset) throws IOException
* @param builder is the target where the <a href="http://en.wikipedia.org/wiki/XML">XML</a> representation
* of <em>knowledge</em> is appended.
* @param knowledge contains the data that will be transformed.
* @throws IllegalArgumentException Thrown if either the <em>builder</em> or the <em>knowledge</em>
* argument is null.
*/
@SuppressWarnings("unchecked")
private void writeKnowledge(StringBuilder builder, Object knowledge) // TODO: check parameters
private void writeKnowledge(StringBuilder builder, Object knowledge)
{
if(builder == null) throw new IllegalArgumentException(String.format(
"The argument \"%s\" is null.", "builder"));
if(knowledge == null) throw new IllegalArgumentException(String.format(
"The argument \"%s\" is null.", "knowledge"));

if(knowledge instanceof Iterable)
{
Iterable<Object> collection = (Iterable<Object>) knowledge;
Expand Down Expand Up @@ -459,14 +473,22 @@ else if(knowledge instanceof Map)
* @param period specifies the period for the repetitive invocation of the given <em>snapshotProvider</em>.
* @throws IOException Thrown if the {@link RuntimeLogger#snapshotPeriodWriter} is unable to be
* written into.
* @throws IllegalArgumentException Thrown if the <em>snapshotProvider</em> argument is null
* or the <em>time</em> is less or equal to 0.
* @throws IllegalArgumentException Thrown if one of the following occurs:
* <ul>
* <li>The <em>snapshotProvider</em> argument is null.</li>
* <li>The <em>period</em> is less or equal to 0.</li>
* <li>The <em>snapshotProvider</em> argument returns null when its {@link SnapshotProvider#getRecordClass()}
* method is called.</li>
* </ul>
*/
public void registerSnapshotProvider(
SnapshotProvider snapshotProvider, long period) throws IOException {
if (snapshotProvider == null)
throw new IllegalArgumentException(String.format(
"The argument \"%s\" is null.", "snapshotProvider"));
if(snapshotProvider.getRecordClass() == null) throw new IllegalArgumentException(
String.format("The %s method invoked on the %s argument returns null.", "getRecordClass()", "snapshotProvider"));

if (scheduler == null) // If not initialized, store the snapshot provider for later
{
snapshotProviders.put(snapshotProvider, period);
Expand All @@ -487,9 +509,10 @@ public void registerSnapshotProvider(
* @param period specifies the time offset to be remembered as a <em>back log offset</em>.
* @throws IOException Thrown if the {@link RuntimeLogger#snapshotPeriodWriter} is unable to be
* written into.
* @throws IllegalArgumentException Thrown if the <em>time</em> is less or equal to 0.
* @throws IllegalArgumentException Thrown if the <em>time</em> is less or equal to 0
* or the <em>snapshotType</em> argument is null.
*/
public void registerSnapshotPeriod(long period, Class<? extends RuntimeLogRecord> snapshotType) throws IOException { // TODO: chect snapshotType != null
public void registerSnapshotPeriod(long period, Class<? extends RuntimeLogRecord> snapshotType) throws IOException {
if (period <= 0) throw new IllegalArgumentException(String.format(
"The argument \"%s\" has to be greater than 0.", "time"));
if(snapshotType == null) throw new IllegalArgumentException(String.format(
Expand Down
Loading

0 comments on commit e76f36f

Please sign in to comment.