1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2018 Make.org
4  *
5  * This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU Affero General Public License as
7  *  published by the Free Software Foundation, either version 3 of the
8  *  License, or (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  *
18  */
19 
20 package org.make.api
21 
22 import akka.actor.testkit.typed.scaladsl.ActorTestKit
23 import akka.actor.typed.ActorSystem
24 import akka.actor.typed.scaladsl.Behaviors
25 import com.typesafe.config.{Config, ConfigFactory}
26 
27 import java.util.concurrent.atomic.AtomicInteger
28 
29 class ShardingActorTest(
30   val actorTesKit: ActorTestKit = ActorTestKit(TestHelper.actorSystemName, TestHelper.fullConfiguration)
31 ) extends ActorTest(actorTesKit.system)
32     with MakeUnitTest
33 
34 object TestHelper {
35   val halfNumberOfPorts: Int = 32768
36   val counter: AtomicInteger = new AtomicInteger(halfNumberOfPorts)
37   val actorSystemName: String = "test_system"
38   def configuration: String = {
39     val port = counter.getAndIncrement()
40     s"""
41        |akka {
42        |  cluster.seed-nodes = ["akka://$actorSystemName@localhost:$port"]
43        |  cluster.jmx.multi-mbeans-in-same-jvm = on
44        |
45        |  persistence {
46        |    journal.plugin = "inmemory-journal"
47        |    snapshot-store.plugin = "inmemory-snapshot-store"
48        |  }
49        |
50        |  remote.artery.canonical {
51        |    port = $port
52        |    hostname = "localhost"
53        |  }
54        |
55        |  test {
56        |    timefactor = 10.0
57        |  }
58        |}
59        |make-api {
60        |  event-sourcing {
61        |    jobs {
62        |      journal = $${inmemory-journal}
63        |      snapshot = $${inmemory-snapshot-store}
64        |    }
65        |    proposals {
66        |      journal = $${inmemory-journal}
67        |      snapshot = $${inmemory-snapshot-store}
68        |    }
69        |    sequences {
70        |      journal = $${inmemory-journal}
71        |      snapshot = $${inmemory-snapshot-store}
72        |    }
73        |    sessions {
74        |      journal = $${inmemory-journal}
75        |      snapshot = $${inmemory-snapshot-store}
76        |    }
77        |    users {
78        |      journal = $${inmemory-journal}
79        |      snapshot = $${inmemory-snapshot-store}
80        |    }
81        |  }
82        |
83        |  kafka {
84        |    connection-string = "nowhere:-1"
85        |    schema-registry = "http://nowhere:-1"
86        |  }
87        |
88        |  cookie-session.lifetime = "600 milliseconds"
89        |  security.secure-hash-salt = "salt-secure"
90        |  security.secure-vote-salt = "vote-secure"
91        |}
92     """.stripMargin
93   }
94 
95   def fullConfiguration: Config =
96     ConfigFactory
97       .parseString(configuration)
98       .withFallback(ConfigFactory.load("default-application.conf"))
99       .resolve()
100 
101   def defaultActorSystem(conf: Config = fullConfiguration): ActorSystem[Nothing] =
102     ActorSystem[Nothing](Behaviors.empty, actorSystemName, conf)
103 }
Line Stmt Id Pos Tree Symbol Tests Code
35 51652 1246 - 1251 Literal <nosymbol> org.make.api.sessionhistory.sessionhistorycoordinatortest 32768
36 51405 1283 - 1319 Apply java.util.concurrent.atomic.AtomicInteger.<init> org.make.api.sessionhistory.sessionhistorycoordinatortest new java.util.concurrent.atomic.AtomicInteger(TestHelper.this.halfNumberOfPorts)
36 51576 1301 - 1318 Select org.make.api.TestHelper.halfNumberOfPorts org.make.api.sessionhistory.sessionhistorycoordinatortest TestHelper.this.halfNumberOfPorts
37 51694 1352 - 1365 Literal <nosymbol> org.make.api.sessionhistory.sessionhistorycoordinatortest "test_system"
39 51514 1413 - 1438 Apply java.util.concurrent.atomic.AtomicInteger.getAndIncrement org.make.api.sessionhistory.sessionhistorycoordinatortest TestHelper.this.counter.getAndIncrement()
92 51426 1443 - 2999 Select scala.collection.StringOps.stripMargin org.make.api.sessionhistory.sessionhistorycoordinatortest scala.Predef.augmentString(("\n |akka {\n | cluster.seed-nodes = [\"akka://".+(TestHelper.this.actorSystemName).+("@localhost:").+(port).+("\"]\n | cluster.jmx.multi-mbeans-in-same-jvm = on\n |\n | persistence {\n | journal.plugin = \"inmemory-journal\"\n | snapshot-store.plugin = \"inmemory-snapshot-store\"\n | }\n |\n | remote.artery.canonical {\n | port = ").+(port).+("\n | hostname = \"localhost\"\n | }\n |\n | test {\n | timefactor = 10.0\n | }\n |}\n |make-api {\n | event-sourcing {\n | jobs {\n | journal = ${inmemory-journal}\n | snapshot = ${inmemory-snapshot-store}\n | }\n | proposals {\n | journal = ${inmemory-journal}\n | snapshot = ${inmemory-snapshot-store}\n | }\n | sequences {\n | journal = ${inmemory-journal}\n | snapshot = ${inmemory-snapshot-store}\n | }\n | sessions {\n | journal = ${inmemory-journal}\n | snapshot = ${inmemory-snapshot-store}\n | }\n | users {\n | journal = ${inmemory-journal}\n | snapshot = ${inmemory-snapshot-store}\n | }\n | }\n |\n | kafka {\n | connection-string = \"nowhere:-1\"\n | schema-registry = \"http://nowhere:-1\"\n | }\n |\n | cookie-session.lifetime = \"600 milliseconds\"\n | security.secure-hash-salt = \"salt-secure\"\n | security.secure-vote-salt = \"vote-secure\"\n |}\n "): String)).stripMargin
99 51717 3043 - 3175 Apply com.typesafe.config.Config.resolve org.make.api.sessionhistory.sessionhistorycoordinatortest com.typesafe.config.ConfigFactory.parseString(TestHelper.this.configuration).withFallback(com.typesafe.config.ConfigFactory.load("default-application.conf")).resolve()
102 51665 3264 - 3324 Apply akka.actor.typed.ActorSystem.apply akka.actor.typed.ActorSystem.apply[Nothing](akka.actor.typed.scaladsl.Behaviors.empty[Nothing], TestHelper.this.actorSystemName, conf)
102 51829 3302 - 3317 Select org.make.api.TestHelper.actorSystemName TestHelper.this.actorSystemName
102 51553 3285 - 3300 TypeApply akka.actor.typed.scaladsl.Behaviors.empty akka.actor.typed.scaladsl.Behaviors.empty[Nothing]