Skip to content

Commit

Permalink
ZEPPELIN-3279. [FlakyTest] NotebookTest.testPerSessionInterpreterClos…
Browse files Browse the repository at this point in the history
…eOnUnbindInterpreterSetting

### What is this PR for?
The root cause of this flaky test is that hashCode doesn't represent an unique id of object. This PR just use IdGenerator for unique id and also combine process id.
This PR also fix the flaky test caused by matplotlib.

### What type of PR is it?
[Bug Fix]

### Todos
* [ ] - Task

### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-3279

### How should this be tested?
* CI Pass

### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Jeff Zhang <zjffdu@apache.org>

Closes apache#2837 from zjffdu/ZEPPELIN-3279 and squashes the following commits:

063d4ee [Jeff Zhang] ZEPPELIN-3279. [FlakyTest] NotebookTest.testPerSessionInterpreterCloseOnUnbindInterpreterSetting
  • Loading branch information
zjffdu committed Mar 6, 2018
1 parent fe660ab commit a6cd0e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion testing/install_external_dependencies.sh
Expand Up @@ -44,6 +44,6 @@ if [[ -n "$PYTHON" ]] ; then
conda update -q conda
conda info -a
conda config --add channels conda-forge
conda install -q matplotlib pandasql ipython=5.4.1 jupyter_client ipykernel matplotlib bokeh=0.12.10
conda install -q matplotlib=2.1.2 pandasql ipython=5.4.1 jupyter_client ipykernel matplotlib bokeh=0.12.10
pip install -q grpcio ggplot bkzep==0.4.0
fi
Expand Up @@ -24,18 +24,27 @@
import org.apache.zeppelin.scheduler.Scheduler;
import org.apache.zeppelin.scheduler.SchedulerFactory;

import java.lang.management.ManagementFactory;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;

public class MockInterpreter1 extends Interpreter {

private static AtomicInteger IdGenerator = new AtomicInteger();

private int object_id;
private String pid;
Map<String, Object> vars = new HashMap<>();

public MockInterpreter1(Properties property) {
super(property);
this.object_id = IdGenerator.getAndIncrement();
this.pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
}

boolean open;


Expand All @@ -60,7 +69,7 @@ public InterpreterResult interpret(String st, InterpreterContext context) {

if ("getId".equals(st)) {
// get unique id of this interpreter instance
result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "" + this.hashCode());
result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "" + this.object_id + "-" + this.pid);
} else if (st.startsWith("sleep")) {
try {
Thread.sleep(Integer.parseInt(st.split(" ")[1]));
Expand Down
Expand Up @@ -44,6 +44,10 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Request;
import org.junit.runner.Result;
import org.mockito.internal.runners.JUnit44RunnerImpl;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -1450,4 +1454,5 @@ public void afterStatusChange(Job job, Status before, Status after) {
private interface StatusChangedListener {
void onStatusChanged(Job job, Status before, Status after);
}

}

0 comments on commit a6cd0e2

Please sign in to comment.