Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Avoid false error messages when launches terminate before exec data h…
Browse files Browse the repository at this point in the history
…as been written.
  • Loading branch information
marchof committed Feb 11, 2012
1 parent 44e0470 commit 2e66757
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
package com.mountainminds.eclemma.internal.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -63,6 +65,7 @@ public void setup() throws IOException {
public void testEmpty() throws Exception {
out.close();
assertNull(dumper.dump());
assertFalse(dumper.hasDataReceived());
}

@Test
Expand All @@ -71,12 +74,15 @@ public void testTwoSessions() throws Exception {
writer.visitClassExecution(new ExecutionData(11, "Clazz1", new boolean[8]));
writer.sendCmdOk();
verifyExecContent(dumper.dump(), "Clazz1");
assertTrue(dumper.hasDataReceived());

writer.visitSessionInfo(new SessionInfo("Session", 10, 20));
writer.visitClassExecution(new ExecutionData(11, "Clazz2", new boolean[8]));
writer.sendCmdOk();
out.close();
verifyExecContent(dumper.dump(), "Clazz2");
assertTrue(dumper.hasDataReceived());

assertNull(dumper.dump());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ public class ExecutionDataDumper {
private final ExecutionDataReader reader;
private final ExecutionDataFiles files;

private boolean dataReceived;

public ExecutionDataDumper(ExecutionDataReader reader,
ExecutionDataFiles files) {
this.reader = reader;
this.files = files;
this.dataReceived = false;
}

public IPath dump() throws IOException, CoreException {
Expand All @@ -47,6 +50,7 @@ public IPath dump() throws IOException, CoreException {
if (sessionInfos.isEmpty()) {
return null;
}
dataReceived = true;
return createDataFile(sessionInfos, executionData);
}

Expand All @@ -62,4 +66,8 @@ private IPath createDataFile(SessionInfoStore sessionInfos,
return file;
}

public boolean hasDataReceived() {
return dataReceived;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class AgentServer extends Job {

private ServerSocket serverSocket;
private RemoteControlWriter writer;
private boolean dataReceived;
private ExecutionDataDumper dumper;

AgentServer(ICoverageLaunch launch, ISessionManager sessionManager,
ExecutionDataFiles files, ICorePreferences preferences) {
Expand All @@ -60,7 +60,6 @@ public class AgentServer extends Job {
this.launch = launch;
this.sessionManager = sessionManager;
this.files = files;
this.dataReceived = false;
}

public void start() throws CoreException {
Expand Down Expand Up @@ -96,7 +95,7 @@ public void stop() {
}

public boolean hasDataReceived() {
return dataReceived;
return dumper != null && dumper.hasDataReceived();
}

public int getPort() {
Expand All @@ -110,15 +109,14 @@ protected IStatus run(IProgressMonitor monitor) {
writer = new RemoteControlWriter(socket.getOutputStream());
final RemoteControlReader reader = new RemoteControlReader(
socket.getInputStream());
final ExecutionDataDumper dumper = new ExecutionDataDumper(reader, files);
dumper = new ExecutionDataDumper(reader, files);
IPath execfile;
while ((execfile = dumper.dump()) != null) {
final CoverageSession session = new CoverageSession(
createDescription(), launch.getScope(), execfile,
launch.getLaunchConfiguration());
sessionManager.addSession(session,
preferences.getActivateNewSessions(), launch);
dataReceived = true;
}
} catch (IOException e) {
return EclEmmaStatus.EXECDATA_DUMP_ERROR.getStatus(e);
Expand Down

0 comments on commit 2e66757

Please sign in to comment.