Skip to content

Commit

Permalink
#6439 Optimalisation of scala test execution. (#6454)
Browse files Browse the repository at this point in the history
* #6439 Optimalisation of scala test execution.

* #6439 Bulk adding import in scala.
  • Loading branch information
michalgce authored and scottdraves committed Dec 6, 2017
1 parent af8ab5d commit ae41dd3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.twosigma.beakerx.scala.evaluator;

import com.google.inject.Provider;
import com.twosigma.beakerx.NamespaceClient;
import com.twosigma.beakerx.autocomplete.AutocompleteResult;
import com.twosigma.beakerx.evaluator.BaseEvaluator;
import com.twosigma.beakerx.NamespaceClient;
import com.twosigma.beakerx.evaluator.JobDescriptor;
import com.twosigma.beakerx.evaluator.TempFolderFactory;
import com.twosigma.beakerx.evaluator.TempFolderFactoryImpl;
Expand All @@ -40,12 +40,11 @@
import com.twosigma.beakerx.scala.serializers.ScalaPrimitiveTypeListOfListSerializer;
import com.twosigma.beakerx.scala.serializers.ScalaPrimitiveTypeMapSerializer;
import com.twosigma.beakerx.scala.serializers.ScalaTableDeSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ScalaEvaluator extends BaseEvaluator {

Expand Down Expand Up @@ -187,14 +186,11 @@ private void newAutoCompleteEvaluator() throws MalformedURLException {
acloader_cp + File.pathSeparatorChar + System.getProperty("java.class.path"), outDir);

if (!imports.isEmpty()) {
for (int i = 0; i < imports.getImportPaths().size(); i++) {
String imp = imports.getImportPaths().get(i).asString().trim();
imp = adjustImport(imp);
if (!imp.isEmpty()) {
if (!acshell.addImport(imp))
logger.warn("ERROR: cannot add import '{}'", imp);
}
}
String[] strings = imports.getImportPaths().stream().map(importPath -> {
String trim = importPath.asString().trim();
return adjustImport(trim);
}).toArray(String[]::new);
acshell.addImports(strings);
}

// ensure object is created
Expand All @@ -214,9 +210,7 @@ void newEvaluator() {
loader_cp + File.pathSeparatorChar + System.getProperty("java.class.path"), getOutDir());

if (!getImports().isEmpty()) {
for (ImportPath importPath : getImports().getImportPaths()) {
addImportToShell(importPath);
}
addImportsToShell(getImports().getImportPaths());
}

logger.debug("creating beaker object");
Expand All @@ -230,6 +224,16 @@ void newEvaluator() {
}
}

private void addImportsToShell(List<ImportPath> importsPaths) {
if (!importsPaths.isEmpty()) {
String[] imp = importsPaths.stream().map(importPath -> adjustImport(importPath.asString())).toArray(String[]::new);
logger.debug("importing : {}", importsPaths);
if (!shell.addImports(imp)) {
logger.warn("ERROR: cannot add import '{}'", imp);
}
}
}

private void addImportToShell(ImportPath importPath) {
String imp = importPath.asString().trim();
imp = adjustImport(imp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class ScalaEvaluatorGlue(val cl: ClassLoader, var cp: String, val replClassdir:
}
}

def addImports(names: Array[String]) : Boolean = {
addImport(names.mkString(", "))
}

def evaluate2(code: String): String = {
baos.reset()
try {
Expand Down

0 comments on commit ae41dd3

Please sign in to comment.