jmh.mbr.core.ResultsWriter Java Examples

The following examples show how to use jmh.mbr.core.ResultsWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MicrobenchmarkResultsWriterFactory.java    From spring-data-dev-tools with Apache License 2.0 5 votes vote down vote up
@Override
public ResultsWriter forUri(String uri) {

	if (uri.startsWith("http")) {
		return new HttpResultsWriter(uri);
	}

	if (uri.startsWith("mongo")) {
		return new MongoResultsWriter(uri);
	}

	return null;
}
 
Example #2
Source File: MongoResultsWriter.java    From spring-data-dev-tools with Apache License 2.0 5 votes vote down vote up
private void doWrite(Collection<RunResult> results) throws ParseException {

		Date now = new Date();
		StandardEnvironment env = new StandardEnvironment();

		String projectVersion = env.getProperty("project.version", "unknown");
		String gitBranch = env.getProperty("git.branch", "unknown");
		String gitDirty = env.getProperty("git.dirty", "no");
		String gitCommitId = env.getProperty("git.commit.id", "unknown");

		ConnectionString uri = new ConnectionString(this.uri);
		MongoClient client = MongoClients.create();

		String dbName = StringUtils.hasText(uri.getDatabase()) ? uri.getDatabase() : "spring-data-mongodb-benchmarks";
		MongoDatabase db = client.getDatabase(dbName);

		String resultsJson = ResultsWriter.jsonifyResults(results).trim();
		JSONArray array = (JSONArray) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(resultsJson);
		for (Object object : array) {
			JSONObject dbo = (JSONObject) object;

			String collectionName = extractClass(dbo.get("benchmark").toString());

			Document sink = new Document();
			sink.append("_version", projectVersion);
			sink.append("_branch", gitBranch);
			sink.append("_commit", gitCommitId);
			sink.append("_dirty", gitDirty);
			sink.append("_method", extractBenchmarkName(dbo.get("benchmark").toString()));
			sink.append("_date", now);
			sink.append("_snapshot", projectVersion.toLowerCase().contains("snapshot"));

			sink.putAll(dbo);

			db.getCollection(collectionName).insertOne(fixDocumentKeys(sink));
		}

		client.close();
	}
 
Example #3
Source File: HttpResultsWriter.java    From spring-data-dev-tools with Apache License 2.0 5 votes vote down vote up
private void doWrite(Collection<RunResult> results) throws IOException {

		StandardEnvironment env = new StandardEnvironment();

		String projectVersion = env.getProperty("project.version", "unknown");
		String gitBranch = env.getProperty("git.branch", "unknown");
		String gitDirty = env.getProperty("git.dirty", "no");
		String gitCommitId = env.getProperty("git.commit.id", "unknown");

		HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
		connection.setConnectTimeout((int) Duration.ofSeconds(1).toMillis());
		connection.setReadTimeout((int) Duration.ofSeconds(1).toMillis());
		connection.setDoOutput(true);
		connection.setRequestMethod("POST");

		connection.setRequestProperty("Content-Type", "application/json");
		connection.addRequestProperty("X-Project-Version", projectVersion);
		connection.addRequestProperty("X-Git-Branch", gitBranch);
		connection.addRequestProperty("X-Git-Dirty", gitDirty);
		connection.addRequestProperty("X-Git-Commit-Id", gitCommitId);

		try (OutputStream output = connection.getOutputStream()) {
			output.write(ResultsWriter.jsonifyResults(results).getBytes(StandardCharsets.UTF_8));
		}

		if (connection.getResponseCode() >= 400) {
			throw new IllegalStateException(
					String.format("Status %d %s", connection.getResponseCode(), connection.getResponseMessage()));
		}
	}