<commit_before>package justin.db.replication

import justin.db.consistent_hashing.Ring
import org.scalatest.{FlatSpec, Matchers}

class PreferenceListTest extends FlatSpec with Matchers {

  behavior of "Preference List"

  it should "has size of defined nr of replicas" in {
    // given
    val n = N(3) // nr of replicas
    val ring = Ring(nodesSize = 5, partitionsSize = 64)
    val basePartitionId = 1

    // when
    val preferenceList = PreferenceList(basePartitionId, n, ring)

    // then
    preferenceList.size shouldBe 3
  }

  it should "has defined first node in the list to be the one taken from Ring with initial partitionId" in {
    // given
    val n = N(3) // nr of replicas
    val ring = Ring(nodesSize = 5, partitionsSize = 64)
    val initialPartitionId = 1

    // when
    val coordinator = PreferenceList.apply(initialPartitionId, n, ring).head

    // then
    coordinator shouldBe ring.getNodeId(initialPartitionId).get
  }

  it should "has at least one member (coordinator) for none replicas" in {
    // given
    val n = N(0) // nr of replicas
    val ring = Ring(nodesSize = 5, partitionsSize = 64)
    val initialPartitionId = 1

    // when
    val preferenceList = PreferenceList.apply(initialPartitionId, n, ring)

    // then
    preferenceList.size shouldBe 1
    preferenceList.head shouldBe ring.getNodeId(initialPartitionId).get
  }
}
<commit_msg>preference list test scenario: "check that selected nodes ids are continuous"<commit_after>package justin.db.replication

import justin.db.consistent_hashing.{NodeId, Ring}
import org.scalatest.{FlatSpec, Matchers}

class PreferenceListTest extends FlatSpec with Matchers {

  behavior of "Preference List"

  it should "has size of defined nr of replicas" in {
    // given
    val n = N(3) // nr of replicas
    val ring = Ring(nodesSize = 5, partitionsSize = 64)
    val basePartitionId = 1

    // when
    val preferenceList = PreferenceList(basePartitionId, n, ring)

    // then
    preferenceList.size shouldBe 3
  }

  it should "has defined first node in the list to be the one taken from Ring with initial partitionId" in {
    // given
    val n = N(3) // nr of replicas
    val ring = Ring(nodesSize = 5, partitionsSize = 64)
    val initialPartitionId = 1

    // when
    val coordinator = PreferenceList.apply(initialPartitionId, n, ring).head

    // then
    coordinator shouldBe ring.getNodeId(initialPartitionId).get
  }

  it should "has at least one member (coordinator) for none replicas" in {
    // given
    val n = N(0) // nr of replicas
    val ring = Ring(nodesSize = 5, partitionsSize = 64)
    val initialPartitionId = 1

    // when
    val preferenceList = PreferenceList.apply(initialPartitionId, n, ring)

    // then
    preferenceList.size shouldBe 1
    preferenceList.head shouldBe ring.getNodeId(initialPartitionId).get
  }

  it should "check that selected nodes ids are continuous" in {
    // given
    val n = N(3) // nr of replicas
    val ring = Ring(nodesSize = 5, partitionsSize = 64)
    val initialPartitionId = 1

    // when
    val preferenceList = PreferenceList.apply(initialPartitionId, n, ring)

    // then
    preferenceList shouldBe List(NodeId(1), NodeId(2), NodeId(3))
  }
}

{'fraction_non_alphanumeric': 0.0842366057602973, 'fraction_numerical': 0.013007122948281201, 'mean_word_length': 3.0375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6988913', 'n_tokens_mistral': 1026, 'n_tokens_neox': 956, 'n_words': 329}