Skip to content

Commit

Permalink
Merge pull request #45 from stokito/tests_refactoring
Browse files Browse the repository at this point in the history
Tests refactoring and cleanup
  • Loading branch information
lvca committed Mar 27, 2015
2 parents e9ef1c0 + e7950dc commit 9b215d5
Show file tree
Hide file tree
Showing 39 changed files with 399 additions and 462 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ pom.xml.next
release.properties

*.iml

3rdy-party-drivers/*
.idea
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.14.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected boolean skip(final Object input) {
throw new OConfigurationException("'if' expression in Transformer " + getName() + " returned '" + result
+ "' instead of boolean");

return !((Boolean) result).booleanValue();
return !(Boolean) result;
}
return false;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ protected Object resolve(final Object iContent) {
if (context == null || iContent == null)
return iContent;

Object value = null;
Object value;
if (iContent instanceof String) {
if (((String) iContent).startsWith("$") && !((String) iContent).startsWith(OSystemVariableResolver.VAR_BEGIN))
value = context.getVariable(iContent.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
* ETL basic component.
*/
public interface OETLComponent {
public ODocument getConfiguration();
ODocument getConfiguration();

public void configure(OETLProcessor iProcessor, ODocument iConfiguration, OBasicCommandContext iSettings);
void configure(OETLProcessor iProcessor, ODocument iConfiguration, OBasicCommandContext iSettings);

public void begin();
void begin();

public void end();
void end();

public String getName();
String getName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
* ETL basic component.
*/
public interface OETLPipelineComponent extends OETLComponent {
public void setPipeline(OETLPipeline iPipeline);
void setPipeline(OETLPipeline iPipeline);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@

import com.orientechnologies.common.exception.OException;

/**
* Created by luca on 30/06/14.
*/
public class OETLProcessHaltedException extends OException {
public OETLProcessHaltedException(Throwable iNested) {
super(iNested);
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/com/orientechnologies/orient/etl/OETLProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ public static void main(final String[] args) {

ODocument configuration = null;

for (int i = 0; i < args.length; ++i) {
final String arg = args[i];

for (final String arg : args) {
if (arg.charAt(0) == '-') {
final String[] parts = arg.substring(1).split("=");
context.setVariable(parts[0].toUpperCase(), parts[1]);
Expand All @@ -146,7 +144,6 @@ public static void main(final String[] args) {
final String config = OIOUtils.readFileAsString(new File(arg));
configuration = new ODocument().fromJSON(config, "noMap");
cfgGlobal = configuration.field("config");

} catch (IOException e) {
throw new OConfigurationException("Error on loading config file: " + arg);
}
Expand All @@ -170,15 +167,15 @@ protected static OBasicCommandContext createDefaultContext() {
}

protected static Collection<ODocument> parseTransformers(final String value) {
final ArrayList<ODocument> cfgTransformers = new ArrayList<ODocument>();
final Collection<ODocument> cfgTransformers = new ArrayList<ODocument>();
if (!value.isEmpty()) {
if (value.charAt(0) == '{') {
cfgTransformers.add((ODocument) new ODocument().fromJSON(value, "noMap"));
cfgTransformers.add(new ODocument().fromJSON(value, "noMap"));
} else if (value.charAt(0) == '[') {
final ArrayList<String> items = new ArrayList<String>();
final List<String> items = new ArrayList<String>();
OStringSerializerHelper.getCollection(value, 0, items);
for (String item : items)
cfgTransformers.add((ODocument) new ODocument().fromJSON(item, "noMap"));
cfgTransformers.add(new ODocument().fromJSON(item, "noMap"));
}
}
return cfgTransformers;
Expand Down Expand Up @@ -420,7 +417,7 @@ public void run() {
}
};

Orient.instance().getTimer().schedule(dumpTask, dumpEveryMs, dumpEveryMs);
Orient.instance().scheduleTask(dumpTask, dumpEveryMs, dumpEveryMs);

startTime = System.currentTimeMillis();
}
Expand Down Expand Up @@ -609,7 +606,7 @@ protected void init() {

final Object parallelSetting = context.getVariable("parallel");
if (parallelSetting != null)
parallel = ((Boolean) parallelSetting).booleanValue();
parallel = (Boolean) parallelSetting;

if (parallel) {
final int cores = Runtime.getRuntime().availableProcessors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public boolean hasNext() {
}
}

@Override
public void end() {
if (reader != null)
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
* ETL Extractor.
*/
public interface OExtractor extends OETLComponent, Iterator<OExtractedItem> {
public void extract(final Reader iReader);
void extract(final Reader iReader);

public long getProgress();
long getProgress();

public long getTotal();
long getTotal();

public String getUnit();
String getUnit();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

package com.orientechnologies.orient.etl.extractor;

/**
* Created by luca on 26/06/14.
*/
public class OExtractorException extends RuntimeException {

public OExtractorException(final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
import java.util.List;
import java.util.NoSuchElementException;

/**
* Created by luca on 04/07/14.
*/
public class OJDBCExtractor extends OAbstractExtractor {
protected String url;
protected String userName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public OExtractedItem next() {
}
}

@Override
public void extract(final Reader iReader) {
super.extract(iReader);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void extract(final Reader iReader) {
bReader = new BufferedReader(reader);
}

@Override
public void end() {
if (bReader != null)
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,24 @@

public class ODefaultImporterListener implements OImporterListener {

@Override
public void onBeforeFile(final ODatabaseDocumentTx db, final OCommandContext iContext) {
}

@Override
public void onAfterFile(final ODatabaseDocumentTx db, final OCommandContext iContext) {
}

@Override
public boolean onBeforeLine(final ODatabaseDocumentTx db, final OCommandContext iContext) {
return true;
}

@Override
public void onAfterLine(final ODatabaseDocumentTx db, final OCommandContext iContext) {
}

@Override
public void onDump(final ODatabaseDocumentTx db, final OCommandContext iContext) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
import com.orientechnologies.orient.core.record.impl.ODocument;

public interface OImporterListener {
public void onBeforeFile(ODatabaseDocumentTx db, OCommandContext iContext);
void onBeforeFile(ODatabaseDocumentTx db, OCommandContext iContext);

public void onAfterFile(ODatabaseDocumentTx db, OCommandContext iContext);
void onAfterFile(ODatabaseDocumentTx db, OCommandContext iContext);

public boolean onBeforeLine(ODatabaseDocumentTx db, OCommandContext iContext);
boolean onBeforeLine(ODatabaseDocumentTx db, OCommandContext iContext);

public void onAfterLine(ODatabaseDocumentTx db, OCommandContext iContext);
void onAfterLine(ODatabaseDocumentTx db, OCommandContext iContext);

public void onDump(ODatabaseDocumentTx db, OCommandContext iContext);
void onDump(ODatabaseDocumentTx db, OCommandContext iContext);

public void onJoinNotFound(ODatabaseDocumentTx db, OCommandContext iContext, final OIndex<?> iIndex, final Object iKey);
void onJoinNotFound(ODatabaseDocumentTx db, OCommandContext iContext, final OIndex<?> iIndex, final Object iKey);

public void validate(ODatabaseDocumentTx db, OCommandContext iContext, ODocument iRecord);
void validate(ODatabaseDocumentTx db, OCommandContext iContext, ODocument iRecord);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,30 @@ public OScriptImporterListener(final Map<String, String> iEvents) {
events = iEvents;
}

@Override
public void onBeforeFile(final ODatabaseDocumentTx db, final OCommandContext iContext) {
executeEvent(db, "onBeforeFile", iContext);
}

@Override
public void onAfterFile(final ODatabaseDocumentTx db, final OCommandContext iContext) {
executeEvent(db, "onAfterFile", iContext);
}

@Override
public boolean onBeforeLine(final ODatabaseDocumentTx db, final OCommandContext iContext) {
final Object ret = executeEvent(db, "onBeforeLine", iContext);
if (ret != null && ret instanceof Boolean)
return (Boolean) ret;
return true;
}

@Override
public void onAfterLine(final ODatabaseDocumentTx db, final OCommandContext iContext) {
executeEvent(db, "onAfterLine", iContext);
}

@Override
public void onDump(final ODatabaseDocumentTx db, final OCommandContext iContext) {
executeEvent(db, "onDump", iContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
* ETL Loader.
*/
public interface OLoader extends OETLPipelineComponent {
public void load(final Object input, OCommandContext context);
void load(final Object input, OCommandContext context);

public long getProgress();
long getProgress();

public String getUnit();
String getUnit();

public void rollback();
void rollback();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

package com.orientechnologies.orient.etl.loader;

/**
* Created by luca on 26/06/14.
*/
public class OLoaderException extends RuntimeException {

public OLoaderException(final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.etl.OETLProcessor;
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
import com.tinkerpop.blueprints.impls.orient.OrientEdge;
import com.tinkerpop.blueprints.impls.orient.OrientElement;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
Expand Down Expand Up @@ -70,6 +69,7 @@ protected enum DB_TYPE {
public OOrientDBLoader() {
}

@Override
public void load(final Object input, OCommandContext context) {
if (input == null)
return;
Expand Down Expand Up @@ -106,8 +106,8 @@ public void load(final Object input, OCommandContext context) {
final OrientElement element = (OrientElement) input;

final OClass cls;
final String clsName = className != null ? className : (element instanceof OrientVertex ? ((OrientVertex) element)
.getLabel() : ((OrientEdge) element).getLabel());
final String clsName = className != null ? className : (element instanceof OrientVertex ? element
.getLabel() : element.getLabel());
if (clsName != null)
cls = getOrCreateClass(clsName, element.getBaseClassName());
else
Expand Down Expand Up @@ -315,6 +315,7 @@ public String getName() {
return "orientdb";
}

@Override
public String getUnit() {
return dbType == DB_TYPE.DOCUMENT ? "documents" : "vertices";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ public class OContentSource extends OAbstractSource {
@Override
public void configure(OETLProcessor iProcessor, ODocument iConfiguration, OBasicCommandContext iContext) {
final Object value = iConfiguration.field("value");

if (value != null) {
String stringContent;
if (value instanceof ODocument)
stringContent = ((ODocument) value).toJSON(null).toString();
stringContent = ((ODocument) value).toJSON(null);
else if (OMultiValue.isMultiValue(value)) {
stringContent = "[";
int i = 0;
Expand All @@ -50,7 +49,7 @@ else if (OMultiValue.isMultiValue(value)) {
stringContent += ",";

if (o instanceof ODocument)
stringContent += ((ODocument) o).toJSON(null).toString();
stringContent += ((ODocument) o).toJSON(null);
else
stringContent += o.toString();
++i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public ODocument getConfiguration() {
return null;
}

@Override
public void configure(OETLProcessor iProcessor, ODocument iConfiguration, OBasicCommandContext iContext) {
super.configure(iProcessor, iConfiguration, iContext);

Expand Down Expand Up @@ -163,8 +164,6 @@ public void begin() {
}

log(OETLProcessor.LOG_LEVELS.DEBUG, "Reading from file " + path);

final long startTime = System.currentTimeMillis();
}

public boolean isClosed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* ETL Source interface.
*/
public interface OSource extends OETLComponent {
public String getUnit();
String getUnit();

public Reader read();
Reader read();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

package com.orientechnologies.orient.etl.source;

/**
* Created by luca on 26/06/14.
*/
public class OSourceException extends RuntimeException {

public OSourceException(final Exception e) {
Expand Down
Loading

0 comments on commit 9b215d5

Please sign in to comment.