<commit_before>package nest.sparkle.measure

import com.typesafe.config.ConfigFactory
import java.nio.charset.StandardCharsets.UTF_8
import java.nio.file.{ Files, Paths }
import nest.sparkle.util.MetricsInstrumentation
import org.scalatest.{ FunSuite, Matchers }
import scala.collection.JavaConverters._
import scala.concurrent.duration._
import java.lang.{ Long => JLong }

class TestMeasurements extends FunSuite with Matchers {

  def withMeasurements(fn: Measurements => Unit) {
    val rootConfig = ConfigFactory.load("testMeasure.conf")
    val measurement = new ConfiguredMeasurements(rootConfig)
    fn(measurement)
  }

  def publishSpan()(implicit measurements: Measurements): String = {
    val name = "short-test"
    val traceId = TraceId("foo") // TODO replace with RandomUtil.RandomAlphaNum
    val span = Span.startNoParent(name, traceId, opsReport=true)
    span.complete()
    name
  }

  test("publish a span to coda-metrics") {
    withMeasurements { implicit measurements =>
      val name = publishSpan()
      val timers = MetricsInstrumentation.registry.getTimers.asScala
      println(s"$timers: {timers.keys.mkString}")
      val x = timers(name)
      x.getCount shouldBe 1
    }
  }

  test("publish a span to a .tsv file") {
    withMeasurements { implicit measurements =>
      val spanName = publishSpan()

      val tsvFile = Paths.get("/tmp/sparkle-measurements.tsv")
      val lines = Files.readAllLines(tsvFile, UTF_8).asScala
      lines.length shouldBe 2
      lines.head shouldBe "name\ttraceId\ttime\tduration"
      val Array(name, traceIdString, timeString, durationString) = lines(1).split("\t")
      name shouldBe spanName
      val time = JLong.parseLong(timeString)
      val duration = JLong.parseLong(durationString)
      val timeToNow = Math.abs(time - System.currentTimeMillis())
      timeToNow should be < 5.seconds.toMillis
      duration / (1000 * 1000) should be < 5.seconds.toMillis 
    }

  }

}<commit_msg>remove debug printout<commit_after>package nest.sparkle.measure

import com.typesafe.config.ConfigFactory
import java.nio.charset.StandardCharsets.UTF_8
import java.nio.file.{ Files, Paths }
import nest.sparkle.util.MetricsInstrumentation
import org.scalatest.{ FunSuite, Matchers }
import scala.collection.JavaConverters._
import scala.concurrent.duration._
import java.lang.{ Long => JLong }

class TestMeasurements extends FunSuite with Matchers {

  def withMeasurements(fn: Measurements => Unit) {
    val rootConfig = ConfigFactory.load("testMeasure.conf")
    val measurement = new ConfiguredMeasurements(rootConfig)
    fn(measurement)
  }

  def publishSpan()(implicit measurements: Measurements): String = {
    val name = "short-test"
    val traceId = TraceId("foo") // TODO replace with RandomUtil.RandomAlphaNum
    val span = Span.startNoParent(name, traceId, opsReport=true)
    span.complete()
    name
  }

  test("publish a span to coda-metrics") {
    withMeasurements { implicit measurements =>
      val name = publishSpan()
      val timers = MetricsInstrumentation.registry.getTimers.asScala
      val x = timers(name)
      x.getCount shouldBe 1
    }
  }

  test("publish a span to a .tsv file") {
    withMeasurements { implicit measurements =>
      val spanName = publishSpan()

      val tsvFile = Paths.get("/tmp/sparkle-measurements.tsv")
      val lines = Files.readAllLines(tsvFile, UTF_8).asScala
      lines.length shouldBe 2
      lines.head shouldBe "name\ttraceId\ttime\tduration"
      val Array(name, traceIdString, timeString, durationString) = lines(1).split("\t")
      name shouldBe spanName
      val time = JLong.parseLong(timeString)
      val duration = JLong.parseLong(durationString)
      val timeToNow = Math.abs(time - System.currentTimeMillis())
      timeToNow should be < 5.seconds.toMillis
      duration / (1000 * 1000) should be < 5.seconds.toMillis 
    }

  }

}
{'fraction_non_alphanumeric': 0.09974293059125965, 'fraction_numerical': 0.007712082262210797, 'mean_word_length': 3.6266349583828776, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3521984', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1166, 'n_words': 282}