File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " effect " : patch
3+ ---
4+
5+ Update existing ` HashRing ` nodes when adding a value with the same primary key.
Original file line number Diff line number Diff line change @@ -145,6 +145,7 @@ export const addMany: {
145145 const key = PrimaryKey . value ( node )
146146 const entry = self . nodes . get ( key )
147147 if ( entry ) {
148+ entry [ 0 ] = node
148149 if ( entry [ 1 ] === weight ) continue
149150 toRemove ??= new Set ( )
150151 toRemove . add ( key )
Original file line number Diff line number Diff line change 1+ import { assert , describe , it } from "@effect/vitest"
2+ import * as HashRing from "effect/HashRing"
3+ import * as PrimaryKey from "effect/PrimaryKey"
4+
5+ describe ( "HashRing" , ( ) => {
6+ it ( "updates the stored node when adding the same primary key" , ( ) => {
7+ const first = {
8+ name : "first" ,
9+ [ PrimaryKey . symbol ] ( ) {
10+ return "node"
11+ }
12+ }
13+ const updated = {
14+ name : "updated" ,
15+ [ PrimaryKey . symbol ] ( ) {
16+ return "node"
17+ }
18+ }
19+ const ring = HashRing . make < typeof first > ( )
20+
21+ HashRing . add ( ring , first )
22+ HashRing . add ( ring , updated )
23+
24+ assert . strictEqual ( HashRing . get ( ring , "request" ) , updated )
25+ } )
26+
27+ it ( "updates the stored node when changing its weight" , ( ) => {
28+ const first = {
29+ name : "first" ,
30+ [ PrimaryKey . symbol ] ( ) {
31+ return "node"
32+ }
33+ }
34+ const updated = {
35+ name : "updated" ,
36+ [ PrimaryKey . symbol ] ( ) {
37+ return "node"
38+ }
39+ }
40+ const ring = HashRing . make < typeof first > ( )
41+
42+ HashRing . add ( ring , first )
43+ HashRing . add ( ring , updated , { weight : 2 } )
44+
45+ assert . strictEqual ( HashRing . get ( ring , "request" ) , updated )
46+ } )
47+ } )
You can’t perform that action at this time.
0 commit comments