<commit_before>package org.cloudcoder.app.loadtester;

import java.util.Arrays;

import org.cloudcoder.app.shared.model.Change;
import org.cloudcoder.app.shared.model.ChangeType;
import org.cloudcoder.app.shared.model.CompilationOutcome;
import org.cloudcoder.app.shared.model.ICallback;
import org.cloudcoder.app.shared.model.SubmissionResult;

public class LoadTesterTask implements Runnable {
	private HostConfig hostConfig;
	private String userName;
	private String password;
	private EditSequence editSequence;
	private int repeatCount;

	public void setHostConfig(HostConfig hostConfig) {
		this.hostConfig = hostConfig;
	}
	
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public void setEditSequence(EditSequence editSequence) {
		this.editSequence = editSequence;
	}
	
	public void setRepeatCount(int repeatCount) {
		this.repeatCount = repeatCount;
	}
	
	@Override
	public void run() {
		try {
			doRun();
		} catch (Exception e) {
			System.err.println("LoadTesterTask caught exception: " + e.toString());
			e.printStackTrace(System.err);
		}
	}

	private void doRun() throws Exception {
		Client client = new Client(hostConfig);
		
		if (!client.login(userName, password)) {
			throw new RuntimeException("Could not log into " + userName + " account");
		}
		
		PlayEditSequence player = new PlayEditSequence();
		player.setClient(client);
		player.setEditSequence(editSequence);
		player.setSubmitOnFullTextChange(true);
		
		player.setOnSend(new ICallback<Change[]>() {
			@Override
			public void call(Change[] value) {
				if (value.length == 1 && value[0].getType() == ChangeType.FULL_TEXT) {
					System.out.print("\u2191");
				} else {
					char[] a = new char[value.length];
					Arrays.fill(a, '.');
					System.out.print(new String(a));
				}
				System.out.flush();<commit_msg>if possible, print username when exception is caught by LoadTesterTask<commit_after>package org.cloudcoder.app.loadtester;

import java.util.Arrays;

import org.cloudcoder.app.shared.model.Change;
import org.cloudcoder.app.shared.model.ChangeType;
import org.cloudcoder.app.shared.model.CompilationOutcome;
import org.cloudcoder.app.shared.model.ICallback;
import org.cloudcoder.app.shared.model.SubmissionResult;
import org.cloudcoder.app.shared.model.User;

public class LoadTesterTask implements Runnable {
	private HostConfig hostConfig;
	private String userName;
	private String password;
	private EditSequence editSequence;
	private int repeatCount;
	private Client client;

	public void setHostConfig(HostConfig hostConfig) {
		this.hostConfig = hostConfig;
	}
	
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public void setEditSequence(EditSequence editSequence) {
		this.editSequence = editSequence;
	}
	
	public void setRepeatCount(int repeatCount) {
		this.repeatCount = repeatCount;
	}
	
	@Override
	public void run() {
		try {
			doRun();
		} catch (Exception e) {
			StringBuilder buf = new StringBuilder();
			buf.append("LoadTesterTask");
			if (client != null && client.getUser() != null) {
				buf.append(" (user=");
				buf.append(client.getUser().getUsername());
				buf.append(")");
			}
			buf.append(" caught exception: " + e.toString());
			e.printStackTrace(System.err);
		}
	}

	private void doRun() throws Exception {
		this.client = new Client(hostConfig);
		
		if (!client.login(userName, password)) {
			throw new RuntimeException("Could not log into " + userName + " account");
		}
		
		PlayEditSequence player = new PlayEditSequence();
		player.setClient(client);
		player.setEditSequence(editSequence);
		player.setSubmitOnFullTextChange(true);
		
		player.setOnSend(new ICallback<Change[]>() {
			@Override
			public void call(Change[] value) {
				if (value.length == 1 && value[0].getType() == ChangeType.FULL_TEXT) {
					System.out.print("\u2191");
				} else {
					char[] a = new char[value.length];
					Arrays.fill(a, '.');
					System.out.print(new String(a));
				}
				System.out.flush();
{'fraction_non_alphanumeric': 0.12045290291496025, 'fraction_numerical': 0.002890869669959046, 'mean_word_length': 4.289171974522293, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4046766', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1278, 'n_words': 280}