|
| 1 | +package org.apache.openwhisk.core.connector.test |
| 2 | + |
| 3 | +import akka.actor.ActorSystem |
| 4 | +import akka.testkit.TestKit |
| 5 | +import org.apache.openwhisk.common.InvokerState.{Healthy, Unhealthy} |
| 6 | +import org.apache.openwhisk.core.connector.InvokerResourceMessage |
| 7 | +import org.apache.openwhisk.core.entity.SchedulerInstanceId |
| 8 | +import org.apache.openwhisk.core.scheduler.{SchedulerEndpoints, SchedulerStates} |
| 9 | +import org.junit.runner.RunWith |
| 10 | +import org.scalatest.junit.JUnitRunner |
| 11 | +import org.scalatest.{FlatSpecLike, Matchers} |
| 12 | + |
| 13 | +@RunWith(classOf[JUnitRunner]) |
| 14 | +class MessageTests extends TestKit(ActorSystem("Message")) with FlatSpecLike with Matchers { |
| 15 | + behavior of "Message" |
| 16 | + |
| 17 | + it should "be able to compare the InvokerResourceMessage" in { |
| 18 | + val msg1 = InvokerResourceMessage(Unhealthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) |
| 19 | + val msg2 = InvokerResourceMessage(Unhealthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) |
| 20 | + |
| 21 | + msg1 == msg2 shouldBe true |
| 22 | + } |
| 23 | + |
| 24 | + it should "be different when the state of InvokerResourceMessage is different" in { |
| 25 | + val msg1 = InvokerResourceMessage(Unhealthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) |
| 26 | + val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) |
| 27 | + |
| 28 | + msg1 != msg2 shouldBe true |
| 29 | + } |
| 30 | + |
| 31 | + it should "be different when the free memory of InvokerResourceMessage is different" in { |
| 32 | + val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) |
| 33 | + val msg2 = InvokerResourceMessage(Healthy.asString, 2048L, 0, 0, Seq.empty, Seq.empty) |
| 34 | + |
| 35 | + msg1 != msg2 shouldBe true |
| 36 | + } |
| 37 | + |
| 38 | + it should "be different when the busy memory of InvokerResourceMessage is different" in { |
| 39 | + val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) |
| 40 | + val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 1024L, 0, Seq.empty, Seq.empty) |
| 41 | + |
| 42 | + msg1 != msg2 shouldBe true |
| 43 | + } |
| 44 | + |
| 45 | + it should "be different when the in-progress memory of InvokerResourceMessage is different" in { |
| 46 | + val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) |
| 47 | + val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 1024L, Seq.empty, Seq.empty) |
| 48 | + |
| 49 | + msg1 != msg2 shouldBe true |
| 50 | + } |
| 51 | + |
| 52 | + it should "be different when the tags of InvokerResourceMessage is different" in { |
| 53 | + val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq("tag1"), Seq.empty) |
| 54 | + val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq("tag1", "tag2"), Seq.empty) |
| 55 | + |
| 56 | + msg1 != msg2 shouldBe true |
| 57 | + } |
| 58 | + |
| 59 | + it should "be different when the dedicated namespaces of InvokerResourceMessage is different" in { |
| 60 | + val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq("ns1")) |
| 61 | + val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq("ns2")) |
| 62 | + |
| 63 | + msg1 != msg2 shouldBe true |
| 64 | + } |
| 65 | + |
| 66 | + it should "be able to compare the SchedulerStates" in { |
| 67 | + val msg1 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 0, SchedulerEndpoints("10.10.10.10", 1234, 1234)) |
| 68 | + val msg2 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 0, SchedulerEndpoints("10.10.10.10", 1234, 1234)) |
| 69 | + |
| 70 | + msg1 == msg2 shouldBe true |
| 71 | + } |
| 72 | + |
| 73 | + it should "be different when the queue size of SchedulerStates is different" in { |
| 74 | + val msg1 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 20, SchedulerEndpoints("10.10.10.10", 1234, 1234)) |
| 75 | + val msg2 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 10, SchedulerEndpoints("10.10.10.10", 1234, 1234)) |
| 76 | + |
| 77 | + msg1 != msg2 shouldBe true |
| 78 | + } |
| 79 | + |
| 80 | + it should "be not different when other than the queue size of SchedulerStates is different" in { |
| 81 | + // only the queue size matter |
| 82 | + val msg1 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 20, SchedulerEndpoints("10.10.10.10", 1234, 1234)) |
| 83 | + val msg2 = SchedulerStates(SchedulerInstanceId("1"), queueSize = 20, SchedulerEndpoints("10.10.10.20", 5678, 5678)) |
| 84 | + |
| 85 | + msg1 == msg2 shouldBe true |
| 86 | + } |
| 87 | +} |
0 commit comments