Skip to content

Commit

Permalink
Fix distributed mode (#26)
Browse files Browse the repository at this point in the history
* fix work in distributed mode

* fix stopAnonymous

* fix raise condition for blazemeter uploader

* fixed delay count
  • Loading branch information
Artem Fedorov authored and undera committed Oct 24, 2017
1 parent 5d275d4 commit 201fc6f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public String startOnline() throws IOException {
}
}


public boolean isTestStarted() {
return test != null;
}

public void sendOnlineData(JSONObject data) throws IOException {
JSONObject session = test.getSession().sendData(data);
int statusCode = session.getInt("statusCode");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void stopAnonymous() throws IOException {
data.put("signature", signature);
data.put("testId", testId);
data.put("sessionId", getId());
httpUtils.query(httpUtils.createPost(uri, data.toString()), 500);
httpUtils.query(httpUtils.createPost(uri, data.toString()), 200);
}

public String getUserId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.List;
import java.util.SortedMap;
import java.util.Stack;
import java.util.TimeZone;
import java.util.TreeMap;

public class LoadosophiaClient implements BackendListenerClient {
Expand Down Expand Up @@ -123,7 +122,7 @@ protected void stop() {
informer.notifyAbout("<p>Uploaded successfully, go to results: <a href='" + redirectLink + "'>" + redirectLink + "</a></p>");
} catch (Throwable ex) {
informer.notifyAbout("Failed to upload results to BM.Sense, see log for detais: " + ex.getMessage());
log.error("Failed to upload results to BM.Sense", ex);
log.error("Failed to upload results (file: '" + fileName + "') to BM.Sense", ex);
}

if (isOnlineInitiated) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicBoolean;

public class LoadosophiaUploader extends BackendListener implements StatusNotifierCallback, Clearable {

Expand All @@ -29,7 +30,8 @@ public class LoadosophiaUploader extends BackendListener implements StatusNotifi
public static final String STORE_DIR = "storeDir";
public static final String USE_ONLINE = "useOnline";

protected ResultCollector resultCollector = new CorrectedResultCollector();
protected static ResultCollector resultCollector = new CorrectedResultCollector();
private static volatile AtomicBoolean isTestStarted = new AtomicBoolean(false);
protected String fileName;
protected LoadosophiaUploaderGui gui;
public static final String FILE_NAME = "fileName";
Expand All @@ -52,14 +54,19 @@ public void testEnded() {

@Override
public void testStarted(String host) {
try {
setupSaving();
} catch (IOException ex) {
log.error("Unable to set up saving config", ex);
final boolean isStarted = isTestStarted.getAndSet(true);
if (!isStarted) {
try {
setupSaving();
} catch (IOException ex) {
log.error("Unable to set up saving config", ex);
}
}
setArguments(createArguments());
super.testStarted(host);
initClient();
if (!isStarted) {
initClient();
}
resultCollector.testStarted(host);
}

Expand All @@ -80,6 +87,7 @@ private Arguments createArguments() {
public void testEnded(String host) {
super.testEnded(host);
resultCollector.testEnded(host);
isTestStarted.set(false);
}

@Override
Expand Down Expand Up @@ -217,4 +225,8 @@ private void initClient() {
@Override
public void clearData() {
}

protected void resetTest() {
isTestStarted.set(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public void handleSampleResults(List<SampleResult> list, BackendListenerContext

accumulator.addAll(list);
JSONObject data = JSONConverter.convertToJSON(accumulator, list);

int counter = 0;
while (!apiClient.isTestStarted() && counter < 3) {
log.debug("Waiting for test starting");
makeDelay();
counter++;
}

try {
apiClient.sendOnlineData(data);
} catch (JMeterStopTestException ex) {
Expand All @@ -90,6 +98,10 @@ public void handleSampleResults(List<SampleResult> list, BackendListenerContext
log.warn("Failed to send data: " + data, e);
}

makeDelay();
}

private void makeDelay() {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import kg.apc.jmeter.notifier.StatusNotifierCallback;

import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicBoolean;

public class BlazeMeterUploader extends BackendListener implements StatusNotifierCallback, Clearable {

Expand All @@ -22,6 +23,7 @@ public class BlazeMeterUploader extends BackendListener implements StatusNotifie
public static final String SHARE_TEST = "share";

protected BlazeMeterUploaderGui gui;
private static volatile AtomicBoolean isTestStarted = new AtomicBoolean(false);

public BlazeMeterUploader() {
super();
Expand All @@ -38,7 +40,9 @@ public void testStarted() {
public void testStarted(String host) {
setArguments(createArguments());
super.testStarted(host);
initClient();
if (!isTestStarted.getAndSet(true)) {
initClient();
}
}

private Arguments createArguments() {
Expand All @@ -56,7 +60,6 @@ public void notifyAbout(String info) {
gui.inform(info);
}
log.info(info);
System.out.println(info);
}

@Override
Expand All @@ -69,6 +72,7 @@ public Object clone() {
@Override
public void testEnded(String host) {
super.testEnded(host);
isTestStarted.set(false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void testTestStarted() {
public void testTestEnded() throws IOException {
System.out.println("testEnded");
LoadosophiaUploader instance = new LoadosophiaUploaderEmul();
instance.resetTest();
instance.setStoreDir(TestJMeterUtils.getTempDir());
instance.setTitle("UnitTest");
instance.setColorFlag("gray");
Expand Down Expand Up @@ -214,6 +215,7 @@ public void testSampleOccurred() {
public void testOnlineProcessor() throws InterruptedException {
System.out.println("onlineProcessor");
LoadosophiaUploader instance = new LoadosophiaUploaderEmul();
instance.resetTest();
instance.setUseOnline(true);
instance.setStoreDir(TestJMeterUtils.getTempDir());
instance.testStarted("");
Expand Down

0 comments on commit 201fc6f

Please sign in to comment.