<commit_before>/*
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package akka.persistence.inmemory.query

import akka.actor.Props
import akka.event.LoggingReceive
import akka.persistence.PersistentActor
import akka.persistence.inmemory.TestSpec
import akka.persistence.query.{AllPersistenceIds, PersistenceQuery}
import akka.stream.ActorMaterializer
import akka.pattern._

class ReadJournalTest extends TestSpec {

  class MyActor(id: Int) extends PersistentActor {
    override val persistenceId: String = "my-" + id

    var state : Int = 0

    override def receiveCommand: Receive = LoggingReceive {
      case "state" ⇒
        sender() ! state

      case event: Int ⇒
        persist(event) { (event: Int) ⇒
          updateState(event)
        }
    }

    def updateState(event: Int): Unit = {
      state = state + event
    }

    override def receiveRecover: Receive = LoggingReceive {
      case event: Int => updateState(event)
    }
  }

  "ReadJournal" should "support AllPersistenceIds" in {
    var actor1 = system.actorOf(Props(new MyActor(1)))
    var actor2 = system.actorOf(Props(new MyActor(2)))

    val readJournal = PersistenceQuery(system).readJournalFor(InMemoryReadJournal.Identifier)
    implicit val mat = ActorMaterializer()

//    readJournal.query(AllPersistenceIds).runFold(List[String]()) { (acc, s) => acc.::(s)}.futureValue.sorted shouldBe List("my-1", "my-2")

    actor1 ! 2
    (actor1 ? "state").futureValue shouldBe 2

    actor2 ! 3
    (actor2 ? "state").futureValue shouldBe 3

    readJournal.query(AllPersistenceIds).runFold(List[String]()) { (acc, s) => acc.::(s)}.futureValue.sorted shouldBe List("my-1", "my-2")
  }

}
<commit_msg>In-memory ReadJournal - support for AllPersistenceIds query<commit_after>/*
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package akka.persistence.inmemory.query

import akka.actor.Props
import akka.event.LoggingReceive
import akka.persistence.PersistentActor
import akka.persistence.inmemory.TestSpec
import akka.persistence.query.{EventsByPersistenceId, AllPersistenceIds, PersistenceQuery}
import akka.stream.ActorMaterializer
import akka.pattern._

class ReadJournalTest extends TestSpec {

  class MyActor(id: Int) extends PersistentActor {
    override val persistenceId: String = "my-" + id

    var state : Int = 0

    override def receiveCommand: Receive = LoggingReceive {
      case "state" ⇒
        sender() ! state

      case event: Int ⇒
        persist(event) { (event: Int) ⇒
          updateState(event)
        }
    }

    def updateState(event: Int): Unit = {
      state = state + event
    }

    override def receiveRecover: Receive = LoggingReceive {
      case event: Int => updateState(event)
    }
  }

  implicit val mat = ActorMaterializer()

  "ReadJournal" should "support AllPersistenceIds" in {
    var actor1 = system.actorOf(Props(new MyActor(1)))
    var actor2 = system.actorOf(Props(new MyActor(2)))

    val readJournal = PersistenceQuery(system).readJournalFor(InMemoryReadJournal.Identifier)

//    readJournal.query(AllPersistenceIds).runFold(List[String]()) { (acc, s) => acc.::(s)}.futureValue.sorted shouldBe List("my-1", "my-2")

    actor1 ! 2
    (actor1 ? "state").futureValue shouldBe 2

    actor2 ! 3
    (actor2 ? "state").futureValue shouldBe 3

    readJournal.query(AllPersistenceIds).runFold(List[String]()) { (acc, s) => acc.::(s)}.futureValue.sorted shouldBe List("my-1", "my-2")
  }

//  it should "not support EventsByPersistenceId" in {
//    val readJournal = PersistenceQuery(system).readJournalFor(InMemoryReadJournal.Identifier)
//    readJournal.query(EventsByPersistenceId("1", 1L, 1L)).runFold(List[String]()) { (acc, ev) => acc.::(ev.event.asInstanceOf[String])}.futureValue.sorted shouldBe List("my-1", "my-2")
//  }

}

{'fraction_non_alphanumeric': 0.11092817452150648, 'fraction_numerical': 0.011319201481786376, 'mean_word_length': 3.764705882352941, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '376068', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1445, 'n_words': 422}