<commit_before>package org.littlewings.infinispan.persistence

import org.infinispan.Cache
import org.infinispan.configuration.cache.{CacheMode, ConfigurationBuilder}
import org.infinispan.manager.DefaultCacheManager

import org.scalatest.FunSpec
import org.scalatest.Matchers._

class SimpleMapCacheStoreSpec extends FunSpec {
  describe("simple map cache store spec") {
    it("persistence") {
      val numInstances = 2

      SimpleMapCacheStore.instances(numInstances)
      withStoreCache[String, String]("storeCache", numInstances) { cache =>
        println(s"Cache size => ${cache.size}")

        val range = 1 to 10

        range.foreach(i => println(s"key[${s"key$i"}] => ${cache.get(s"key$i")}"))

        (1 to 10) foreach (i => cache.put(s"key$i", s"value$i"))

        /*
        println("Wait...")
        Thread.sleep(5000L)

        range.foreach(i => println(s"key[${s"key$i"}] => ${cache.get(s"key$i")}"))
        */
      }
    }
  }

  def withStoreCache[K, V](cacheName: String, numInstances: Int = 1)(fun: Cache[K, V] => Unit): Unit = {
    val managers =
    (1 to numInstances).map { _ =>
      val manager = new DefaultCacheManager("infinispan.xml")

      val persistenceBuilder = new ConfigurationBuilder()
        .clustering
        .cacheMode(CacheMode.DIST_SYNC)
        .expiration<commit_msg>TestCode to lazy cluster startup<commit_after>package org.littlewings.infinispan.persistence

import org.infinispan.Cache
import org.infinispan.configuration.cache.{CacheMode, ConfigurationBuilder}
import org.infinispan.manager.DefaultCacheManager

import org.scalatest.FunSpec
import org.scalatest.Matchers._

class SimpleMapCacheStoreSpec extends FunSpec {
  describe("simple map cache store spec") {
    it("persistence") {
      val storeSize = 2
      val numInstances = 1

      SimpleMapCacheStore.instances(storeSize)
      withStoreCache[String, String]("storeCache", numInstances) { cache =>
        println(s"Cache size => ${cache.size}")

        val range = 1 to 10

        (1 to 3).foreach(i => cache.remove(s"key$i"))
        (4 to 6).foreach(i => cache.put(s"key$i", "valueXXXXX"))

        range.foreach(i => println(s"key[${s"key$i"}] => ${cache.get(s"key$i")}"))

        withStoreCache[String, String]("storeCache", numInstances) { cache2 =>
          range.foreach(i => println(s"key[${s"key$i"}] => ${cache2.get(s"key$i")}"))
          (1 to 10) foreach (i => cache2.put(s"key$i", s"value$i"))
        }
        
        // (1 to 10) foreach (i => cache.put(s"key$i", s"value$i"))

        /*
        println("Wait...")
        Thread.sleep(5000L)

        range.foreach(i => println(s"key[${s"key$i"}] => ${cache.get(s"key$i")}"))
        */
      }
    }
  }

  def withStoreCache[K, V](cacheName: String, numInstances: Int = 1)(fun: Cache[K, V] => Unit): Unit = {
    val managers =
    (1 to numInstances).map { _ =>
      val manager = new DefaultCacheManager("infinispan.xml")

      val persistenceBuilder = new ConfigurationBuilder()
        .clustering
        .cacheMode(CacheMode.DIST_SYNC)
        .expiration
{'fraction_non_alphanumeric': 0.15294500488122356, 'fraction_numerical': 0.012040351448096323, 'mean_word_length': 3.176630434782609, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7326620', 'n_tokens_mistral': 1049, 'n_tokens_neox': 992, 'n_words': 191}