package com.flozano.statsd.metrics.example;

import java.time.Clock;

import org.junit.Test;

import com.flozano.statsd.metrics.Metrics;
import com.flozano.statsd.metrics.MetricsBuilder;
import com.flozano.statsd.metrics.Timer.TimeKeeping;

public class Example {

	@Test
	public void withBuilder() throws Exception {
		try (Metrics metrics = MetricsBuilder.create()
				.withClient((clientBuilder) -> //
						clientBuilder.withHost("127.0.0.1") //
								.withPort(8125) //
								.withSampleRate(0.5) //
				).withClock(Clock.systemUTC()).build()) {
			metrics.counter("visitors").hit();
			metrics.counter("soldItems").count(25);
			metrics.gauge("activeDatabaseConnections").value(
					getConnectionsFromPool());
			metrics.gauge("activeSessions").delta(-1);

			try (TimeKeeping o = metrics.timer("timeSpentSavingData").time()) {
				saveData();
			}
		}
	}

	private static long getConnectionsFromPool() {
		return 10;
	}

	private static void saveData() {
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}

@@ -282,19 +282,14 @@
 oid 
-withBuilder
+simple
 () t
@@ -852,24 +852,802 @@
 %09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A
+%09@Test%0A%09public void batch() throws Exception %7B%0A%09%09try (Metrics metrics = MetricsBuilder.create()%0A%09%09%09%09.withClient((clientBuilder) -%3E //%0A%09%09%09%09%09%09clientBuilder.withHost(%22127.0.0.1%22) //%0A%09%09%09%09%09%09%09%09.withPort(8125) //%0A%09%09%09%09%09%09%09%09.withSampleRate(0.5) //%0A%09%09%09%09).withClock(Clock.systemUTC()).build()) %7B%0A%0A%09%09%09// Send a counter metric immediately%0A%09%09%09metrics.counter(%22visitors%22).hit();%0A%0A%09%09%09// Create a batch of metrics that will be sent at the end of the try%0A%09%09%09// block.%0A%09%09%09try (Metrics batch = metrics.batch()) %7B%0A%09%09%09%09batch.gauge(%22activeDatabaseConnections%22).value(%0A%09%09%09%09%09%09getConnectionsFromPool());%0A%09%09%09%09batch.gauge(%22activeSessions%22).delta(-1);%0A%09%09%09%7D%0A%0A%09%09%09// Measure the time spent inside the try block%0A%09%09%09try (TimeKeeping o = metrics.timer(%22timeSpentSavingData%22).time()) %7B%0A%09%09%09%09saveData();%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A
 %09private sta

Improve and document a little the example class