11package com .playtika .shepherd ;
22
3+ import com .playtika .shepherd .common .AssignmentData ;
34import com .playtika .shepherd .common .push .Pasture ;
45import com .playtika .shepherd .common .push .Shepherd ;
56import org .junit .jupiter .api .Test ;
@@ -37,8 +38,8 @@ public void shouldBalanceStaticHerd() {
3738 AtomicReference <List <ByteBuffer >> cows1 = new AtomicReference <>(List .of ());
3839
3940 String herdName = "push-static-herd" ;
40- Pasture <ByteBuffer > pasture1 = kafkaRanch .addPasture (herdName , (population , version , generation , isLeader ) -> {
41- logPopulation (1 , population , version , isLeader );
41+ Pasture <ByteBuffer > pasture1 = kafkaRanch .addPasture (herdName , (population , assignmentData ) -> {
42+ logPopulation (1 , population , assignmentData );
4243 cows1 .set (population );
4344 });
4445
@@ -51,8 +52,8 @@ public void shouldBalanceStaticHerd() {
5152
5253 //setup another pasture
5354 AtomicReference <List <ByteBuffer >> cows2 = new AtomicReference <>(List .of ());
54- Pasture <ByteBuffer > pasture2 = kafkaRanch .addPasture (herdName , (population , version , generation , isLeader ) -> {
55- logPopulation (2 , population , version , isLeader );
55+ Pasture <ByteBuffer > pasture2 = kafkaRanch .addPasture (herdName , (population , assignmentData ) -> {
56+ logPopulation (2 , population , assignmentData );
5657 cows2 .set (population );
5758 });
5859 pasture2 .getShepherd ().setPopulation (cows , -1 );
@@ -65,8 +66,8 @@ public void shouldBalanceStaticHerd() {
6566
6667 //setup third pasture
6768 AtomicReference <List <ByteBuffer >> cows3 = new AtomicReference <>(List .of ());
68- Pasture <ByteBuffer > pasture3 = kafkaRanch .addPasture (herdName , (population , version , generation , isLeader ) -> {
69- logPopulation (3 , population , version , isLeader );
69+ Pasture <ByteBuffer > pasture3 = kafkaRanch .addPasture (herdName , (population , assignmentData ) -> {
70+ logPopulation (3 , population , assignmentData );
7071 cows3 .set (population );
7172 });
7273 pasture3 .getShepherd ().setPopulation (cows , -1 );
@@ -113,20 +114,20 @@ private void shouldBalanceDynamicHerd(boolean versioned) {
113114 AtomicReference <List <ByteBuffer >> cows1 = new AtomicReference <>(List .of ());
114115 AtomicLong version1 = new AtomicLong ();
115116 String herdName = versioned ? "push-dynamic-group-versioned" : "push-dynamic-group" ;
116- Pasture <ByteBuffer > pasture1 = kafkaRanch .addPasture (herdName , (population , version , generation , isLeader ) -> {
117- logPopulation (1 , population , version , isLeader );
117+ Pasture <ByteBuffer > pasture1 = kafkaRanch .addPasture (herdName , (population , assignmentData ) -> {
118+ logPopulation (1 , population , assignmentData );
118119 cows1 .set (population );
119- version1 .set (version );
120+ version1 .set (assignmentData . populationVersion () );
120121 });
121122 pasture1 .getShepherd ().setPopulation (cows , ver1 );
122123 pasture1 .start ();
123124
124125 AtomicReference <List <ByteBuffer >> cows2 = new AtomicReference <>(List .of ());
125126 AtomicLong version2 = new AtomicLong ();
126- Pasture <ByteBuffer > pasture2 = kafkaRanch .addPasture (herdName , (population , version , generation , isLeader ) -> {
127- logPopulation (2 , population , version , isLeader );
127+ Pasture <ByteBuffer > pasture2 = kafkaRanch .addPasture (herdName , (population , assignmentData ) -> {
128+ logPopulation (2 , population , assignmentData );
128129 cows2 .set (population );
129- version2 .set (version );
130+ version2 .set (assignmentData . populationVersion () );
130131 });
131132 pasture2 .getShepherd ().setPopulation (cows , ver1 );
132133 pasture2 .start ();
@@ -212,16 +213,16 @@ public void shouldBalanceDynamicConcurrentSequenceHerd() {
212213
213214 AtomicReference <List <ByteBuffer >> cows1 = new AtomicReference <>(List .of ());
214215 String herdName = "push-random-group" ;
215- Pasture <ByteBuffer > pasture1 = kafkaRanch .addPasture (herdName , (population , version , generation , isLeader ) -> {
216- logPopulation (1 , population , version , isLeader );
216+ Pasture <ByteBuffer > pasture1 = kafkaRanch .addPasture (herdName , (population , assignmentData ) -> {
217+ logPopulation (1 , population , assignmentData );
217218 cows1 .set (population );
218219 });
219220 pasture1 .getShepherd ().setPopulation (new ByteBuffer []{}, 0 );
220221 pasture1 .start ();
221222
222223 AtomicReference <List <ByteBuffer >> cows2 = new AtomicReference <>(List .of ());
223- Pasture <ByteBuffer > pasture2 = kafkaRanch .addPasture (herdName , (population , version , generation , isLeader ) -> {
224- logPopulation (2 , population , version , isLeader );
224+ Pasture <ByteBuffer > pasture2 = kafkaRanch .addPasture (herdName , (population , assignmentData ) -> {
225+ logPopulation (2 , population , assignmentData );
225226 cows2 .set (population );
226227 });
227228 pasture2 .getShepherd ().setPopulation (new ByteBuffer []{}, 0 );
@@ -274,8 +275,7 @@ public void shouldBalanceBreedingStaticHerd() {
274275 AtomicReference <List <BlackSheep >> subHerd1 = new AtomicReference <>(List .of ());
275276
276277 String herdName = "push-static-breeding-herd" ;
277- Pasture <BlackSheep > pasture1 = kafkaRanch .addBreedingPasture (herdName , BlackSheep .class ,
278- (population , version , generation , isLeader ) -> {
278+ Pasture <BlackSheep > pasture1 = kafkaRanch .addBreedingPasture (herdName , BlackSheep .class , (population , assignmentData ) -> {
279279 logger .info ("Assigned sheep1 [{}]" , population );
280280 subHerd1 .set (population );
281281 });
@@ -289,8 +289,7 @@ public void shouldBalanceBreedingStaticHerd() {
289289
290290 //setup another pasture
291291 AtomicReference <List <BlackSheep >> subHerd2 = new AtomicReference <>(List .of ());
292- Pasture <BlackSheep > pasture2 = kafkaRanch .addBreedingPasture (herdName , BlackSheep .class ,
293- (population , version , generation , isLeader ) -> {
292+ Pasture <BlackSheep > pasture2 = kafkaRanch .addBreedingPasture (herdName , BlackSheep .class , (population , assignmentData ) -> {
294293 logger .info ("Assigned sheep2 [{}]" , population );
295294 subHerd2 .set (population );
296295 });
@@ -304,7 +303,7 @@ public void shouldBalanceBreedingStaticHerd() {
304303
305304 //setup third pasture
306305 AtomicReference <List <BlackSheep >> subHerd3 = new AtomicReference <>(List .of ());
307- Pasture <BlackSheep > pasture3 = kafkaRanch .addBreedingPasture (herdName , BlackSheep .class , (population , version , generation , isLeader ) -> {
306+ Pasture <BlackSheep > pasture3 = kafkaRanch .addBreedingPasture (herdName , BlackSheep .class , (population , assignmentData ) -> {
308307 logger .info ("Assigned cows3 [{}]" , population );
309308 subHerd3 .set (population );
310309 });
@@ -326,8 +325,8 @@ public void shouldBalanceBreedingStaticHerd() {
326325 });
327326 }
328327
329- private static void logPopulation (int pastureIndex , List <ByteBuffer > population , long version , boolean isLeader ) {
330- logger .info ("Assigned to pasture{} leader ={} version={} [{}]" , pastureIndex , isLeader , version , toBytes (population ));
328+ private static void logPopulation (int pastureIndex , List <ByteBuffer > population , AssignmentData assignmentData ) {
329+ logger .info ("Assigned to pasture{} assignmentData ={} [{}]" , pastureIndex , assignmentData , toBytes (population ));
331330 }
332331
333332 static class BlackSheep {
0 commit comments