<commit_before>package com.akkademy

import org.scalatest.{FunSpecLike, Matchers}
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.language.postfixOps
import com.akkademy.messages._


class AkkademyDbClientSpec extends FunSpecLike with Matchers {

  private val serverAddr = "127.0.0.1:2552" 

  describe("akkademydb-client") {

    val client = new AkkademyDbClient(serverAddr)

    val timeout = 2 seconds

    it("should set a value and then get the same value") {
      val k = "key-1"
      val v = 123 

      val f1 = client.set(k, v)
      val rs1 = Await.result(f1, timeout)
      rs1 should equal(None)

      val f2 = client.get(k)
      val rs2 = Await.result(f2, timeout)
      rs2 should equal(v)
    }

    it("should set a value and then delete it") {
      val k = "key-2"
      val v = "blah"

      val f1 = client.set(k, v)
      val rs1 = Await.result(f1, timeout)
      rs1 should equal(None)

      val f2 = client.delete(k)
      val rs2 = Await.result(f2, timeout)
      rs2 should equal(v)

      val f3 = client.get(k)
      intercept[KeyNotFound] {
        Await.result(f3, timeout)
      }
    }

    it("should set a value that does not already exist (using SetIfNotExists)") {
      val k = "key-3"
      val v = 123.45 

      val f1 = client.setIfNotExists(k, v)
      val rs1 = Await.result(f1, timeout)
      rs1 should equal(v)

      val f2 = client.get(k)
      val rs2 = Await.result(f2, timeout)
      rs2 should equal(v)
    }

    it("should not set a value that already exists (using SetIfNotExists)") {
      val k = "key-4"
      val v1 = true 
      val v2 = false 

      val f1 = client.set(k, v1)
      val rs1 = Await.result(f1, timeout)
      rs1 should equal(None)

      val f2 = client.setIfNotExists(k, v2)
      val rs2 = Await.result(f2, timeout)
      rs2 should equal(v1)

      val f3 = client.get(k)
      val rs3 = Await.result(f3, timeout)
      rs3 should equal(v1)
    }

    it("should fail when key is not found for a get") {
      val f1 = client.get("r6*me@")
      intercept[KeyNotFound] {
        Await.result(f1, timeout)
      } 
    }

    it("should fail when key is not found for a delete") {
      val f1 = client.delete("-gaJ(n")
      intercept[KeyNotFound] {
        Await.result(f1, timeout)
      } 
    }

    it("should fail when sent an unexpected message") {
      val f1 = client.sendUnexpected("junk") <commit_msg>Update tests<commit_after>package com.akkademy

import org.scalatest.{FunSpecLike, Matchers}
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.language.postfixOps
import com.akkademy.messages._


class AkkademyDbClientSpec extends FunSpecLike with Matchers {

  private val serverAddr = "127.0.0.1:2552" 

  private val client = new AkkademyDbClient(serverAddr)

  private val timeout = 2 seconds

  describe("set() and get()") {
    it("should set a value and then get the same value back") {
      val k = "key-1"
      val v = 123 

      val f1 = client.set(k, v)
      val rs1 = Await.result(f1, timeout)
      rs1 should equal(None)

      val f2 = client.get(k)
      val rs2 = Await.result(f2, timeout)
      rs2 should equal(v)
    }
  }

  describe("set()") {
    it("should return the old value if an existing key is updated") {
      val k = "key-1"
      val v1 = Some(123)
      val v2 = 456

      val f1 = client.set(k, v2)
      val rs1 = Await.result(f1, timeout)
      rs1 should equal(v1)

      val f2 = client.get(k)
      val rs2 = Await.result(f2, timeout)
      rs2 should equal(v2)
    }
  }

  describe("set(), delete(), and get()") {
    it("should set a value, delete it, and then get a KeyNotFound") {
      val k = "key-2"
      val v = "blah"

      val f1 = client.set(k, v)
      val rs1 = Await.result(f1, timeout)
      rs1 should equal(None)

      val f2 = client.delete(k)
      val rs2 = Await.result(f2, timeout)
      rs2 should equal(v)

      val f3 = client.get(k)
      intercept[KeyNotFound] {
        Await.result(f3, timeout)
      }
    }
  }

  describe("setIfNotExists()") {
    it("should set a value that does not already exist") {
      val k = "key-3"
      val v = 123.45 

      val f1 = client.setIfNotExists(k, v)
      val rs1 = Await.result(f1, timeout)
      rs1 should equal(v)

      val f2 = client.get(k)
      val rs2 = Await.result(f2, timeout)
      rs2 should equal(v)
    }

    it("should not set a value that already exists") {
      val k = "key-4"
      val v1 = true 
      val v2 = false 

      val f1 = client.set(k, v1)
      val rs1 = Await.result(f1, timeout)
      rs1 should equal(None)

      val f2 = client.setIfNotExists(k, v2)
      val rs2 = Await.result(f2, timeout)
      rs2 should equal(v1)

      val f3 = client.get(k)
      val rs3 = Await.result(f3, timeout)
      rs3 should equal(v1)
    }
  }

  describe("get()") {
    it("should fail when key is not found") {
      val f1 = client.get("r6*me@")
      intercept[KeyNotFound] {
        Await.result(f1, timeout)
      } 
    }
  }

  describe("delete()") {
    it("should fail when key is not found") {
      val f1 = client.delete("-gaJ(n")
      intercept[KeyNotFound] {
        Await.result(f1, timeout)
      } 
    }
  }

  describe("sendUnexpected()") {
    it("should fail when sent a message") {
      val f1 = client.sendUnexpected("junk") 
{'fraction_non_alphanumeric': 0.11415780637940683, 'fraction_numerical': 0.030964372318597277, 'mean_word_length': 2.2775061124694376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4266744', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1864, 'n_words': 530}