-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compare func for schedule replica
- Loading branch information
1 parent
80d8fba
commit b96ed25
Showing
4 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,44 @@ | ||
package prophet | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRandResource(t *testing.T) { | ||
m := make(map[uint64]*ResourceRuntime) | ||
|
||
res := newTestResource() | ||
res.ResID = 2 | ||
m[2] = &ResourceRuntime{ | ||
meta: res, | ||
leaderPeer: &Peer{}, | ||
} | ||
|
||
res = newTestResource() | ||
res.ResID = 10 | ||
m[10] = &ResourceRuntime{ | ||
meta: res, | ||
leaderPeer: &Peer{}, | ||
} | ||
|
||
res = newTestResource() | ||
res.ResID = 1 | ||
m[1] = &ResourceRuntime{ | ||
meta: res, | ||
leaderPeer: &Peer{}, | ||
} | ||
|
||
value := randResource(m, ReplicaKind, func(res1, res2 Resource) int { | ||
if res1.ID() == res2.ID() { | ||
return 0 | ||
} else if res1.ID() > res2.ID() { | ||
return 1 | ||
} else { | ||
return -1 | ||
} | ||
}) | ||
assert.NotNil(t, value, "TestRandResource failed") | ||
assert.Equal(t, uint64(1), value.meta.ID(), "TestRandResource failed") | ||
} |