patterntesting.runtime.log.ObjectPlayer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of patterntesting-rt Show documentation
Show all versions of patterntesting-rt Show documentation
PatternTesting Runtime (patterntesting-rt) is the runtime component for
the PatternTesting framework. It provides the annotations and base classes
for the PatternTesting testing framework (e.g. patterntesting-check,
patterntesting-concurrent or patterntesting-exception) but can be also
used standalone for classpath monitoring or profiling.
It uses AOP and AspectJ to perform this feat.
/*
* Copyright (c) 2013 by Oli B.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* (c)reated 31.08.2013 by Oli B. ([email protected])
*/
package patterntesting.runtime.log;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.ObjectUtils;
import org.aspectj.lang.JoinPoint;
import org.slf4j.*;
import patterntesting.runtime.io.*;
import patterntesting.runtime.util.*;
/**
* This is the counterpart to {@link ObjectRecorder} class. It can be used to
* replay recorded objects.
*
* @author oliver ([email protected])
* @since 1.3.1 (31.08.2013)
*/
public final class ObjectPlayer {
private static final Logger log = LoggerFactory.getLogger(ObjectPlayer.class);
private static final AbstractSerializer serializer = AbstractSerializer.getInstance();
private final Map> loggedJoinpoints = new HashMap>();
/**
* Instantiates a new object player. The logged objects will be loaded from
* the given log file.
*
* @param logFile the log file
* @throws IOException Signals that an I/O exception has occurred.
*/
public ObjectPlayer(final File logFile) throws IOException {
load(logFile);
}
/**
* Gets the return value for the given joinpoint. The return values are
* returned in the same order as the were recorded. I.e. if for the same
* joinpoint first the value "1" and then the value "2" is recorded you'll
* get first "1", then "2" as the return value.
*
* @param joinPoint the join point
* @return the return value
*/
public Object getReturnValue(final JoinPoint joinPoint) {
String statement = JoinPointHelper.getAsLongString(joinPoint);
if (SignatureHelper.hasReturnType(joinPoint.getSignature())) {
return getReturnValue(statement);
}
log.debug("REPLAY: {}", statement);
return null;
}
private Object getReturnValue(final String joinPoint) {
Object returnValue = null;
if (loggedJoinpoints.containsKey(joinPoint)) {
List