-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Do not put data to ETCD when no date is changed. #5291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7100647
Do not put data to ETCD when no date is changed.
style95 9402d57
Update the hashcode calculation.
style95 f25273d
Take dedicated namespace into account when calculating the hash code.
style95 8252a58
Apply the comment.
style95 ca75f44
Apply the comment.
style95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -389,6 +389,24 @@ case class SchedulerStates(sid: SchedulerInstanceId, queueSize: Int, endpoints: | |
def getSchedulerId(): SchedulerInstanceId = sid | ||
|
||
def serialize = SchedulerStates.serdes.write(this).compactPrint | ||
|
||
def canEqual(a: Any) = a.isInstanceOf[SchedulerStates] | ||
|
||
override def equals(that: Any): Boolean = | ||
that match { | ||
case that: SchedulerStates => { | ||
that.canEqual(this) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't required either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
this.queueSize == that.queueSize | ||
} | ||
case _ => false | ||
} | ||
|
||
override def hashCode: Int = { | ||
var result = 1 | ||
val prime = 31 | ||
result = prime * result + queueSize.hashCode() | ||
result | ||
} | ||
} | ||
|
||
object SchedulerStates extends DefaultJsonProtocol { | ||
|
87 changes: 87 additions & 0 deletions
87
tests/src/test/scala/org/apache/openwhisk/core/connector/test/MessageTests.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.apache.openwhisk.core.connector.test | ||
|
||
import akka.actor.ActorSystem | ||
import akka.testkit.TestKit | ||
import org.apache.openwhisk.common.InvokerState.{Healthy, Unhealthy} | ||
import org.apache.openwhisk.core.connector.InvokerResourceMessage | ||
import org.apache.openwhisk.core.entity.SchedulerInstanceId | ||
import org.apache.openwhisk.core.scheduler.{SchedulerEndpoints, SchedulerStates} | ||
import org.junit.runner.RunWith | ||
import org.scalatest.junit.JUnitRunner | ||
import org.scalatest.{FlatSpecLike, Matchers} | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class MessageTests extends TestKit(ActorSystem("Message")) with FlatSpecLike with Matchers { | ||
behavior of "Message" | ||
|
||
it should "be able to compare the InvokerResourceMessage" in { | ||
val msg1 = InvokerResourceMessage(Unhealthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) | ||
val msg2 = InvokerResourceMessage(Unhealthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) | ||
|
||
msg1 == msg2 shouldBe true | ||
} | ||
|
||
it should "be different when the state of InvokerResourceMessage is different" in { | ||
val msg1 = InvokerResourceMessage(Unhealthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) | ||
val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) | ||
|
||
msg1 != msg2 shouldBe true | ||
} | ||
|
||
it should "be different when the free memory of InvokerResourceMessage is different" in { | ||
val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) | ||
val msg2 = InvokerResourceMessage(Healthy.asString, 2048L, 0, 0, Seq.empty, Seq.empty) | ||
|
||
msg1 != msg2 shouldBe true | ||
} | ||
|
||
it should "be different when the busy memory of InvokerResourceMessage is different" in { | ||
val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) | ||
val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 1024L, 0, Seq.empty, Seq.empty) | ||
|
||
msg1 != msg2 shouldBe true | ||
} | ||
|
||
it should "be different when the in-progress memory of InvokerResourceMessage is different" in { | ||
val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty) | ||
val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 1024L, Seq.empty, Seq.empty) | ||
|
||
msg1 != msg2 shouldBe true | ||
} | ||
|
||
it should "be different when the tags of InvokerResourceMessage is different" in { | ||
val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq("tag1"), Seq.empty) | ||
val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq("tag1", "tag2"), Seq.empty) | ||
|
||
msg1 != msg2 shouldBe true | ||
} | ||
|
||
it should "be different when the dedicated namespaces of InvokerResourceMessage is different" in { | ||
val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq("ns1")) | ||
val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq("ns2")) | ||
|
||
msg1 != msg2 shouldBe true | ||
} | ||
|
||
it should "be able to compare the SchedulerStates" in { | ||
val msg1 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 0, SchedulerEndpoints("10.10.10.10", 1234, 1234)) | ||
val msg2 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 0, SchedulerEndpoints("10.10.10.10", 1234, 1234)) | ||
|
||
msg1 == msg2 shouldBe true | ||
} | ||
|
||
it should "be different when the queue size of SchedulerStates is different" in { | ||
val msg1 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 20, SchedulerEndpoints("10.10.10.10", 1234, 1234)) | ||
val msg2 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 10, SchedulerEndpoints("10.10.10.10", 1234, 1234)) | ||
|
||
msg1 != msg2 shouldBe true | ||
} | ||
|
||
it should "be not different when other than the queue size of SchedulerStates is different" in { | ||
// only the queue size matter | ||
val msg1 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 20, SchedulerEndpoints("10.10.10.10", 1234, 1234)) | ||
val msg2 = SchedulerStates(SchedulerInstanceId("1"), queueSize = 20, SchedulerEndpoints("10.10.10.20", 5678, 5678)) | ||
|
||
msg1 == msg2 shouldBe true | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data management service compares the message to decide whether to put data or not.
https://github.com/apache/openwhisk/blob/master/common/scala/src/main/scala/org/apache/openwhisk/core/service/DataManagementService.scala#L161
So we need to override the
equals
method to make it compare messages with==
.