-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the OnlineRadixSorter yet again, this time to use a sorted map…
… to allow for chaining. In addition to chaining sequential stages together (which now, again, need to create all intermediates before the current work item), the class now emits which sequential stages are missing (outstanding) in the DCF's diagnostic supplier. Sample output may look like this [504336483] Caller-task completion for idx=3[…]<-[335107734] OnlineRadixSorterForIntegratedKeys.addFutureForWork[…]<-[215078753] Kickoff for slot #3[…]<-[1384454980] Work to finish for slot #2 is awaiting [slotsOutstanding:2][…] Signed-off-by: Greg Schohn <greg.schohn@gmail.com>
- Loading branch information
1 parent
030f91c
commit e8305a7
Showing
5 changed files
with
99 additions
and
57 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
35 changes: 23 additions & 12 deletions
35
...icReplayer/src/test/java/org/opensearch/migrations/replay/util/OnlineRadixSorterTest.java
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 |
---|---|---|
@@ -1,44 +1,55 @@ | ||
package org.opensearch.migrations.replay.util; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@Slf4j | ||
class OnlineRadixSorterTest { | ||
|
||
private static String stringify(Stream<Integer> stream) { | ||
return stream.map(i->i.toString()).collect(Collectors.joining(",")); | ||
return stream.map(Object::toString).collect(Collectors.joining(",")); | ||
} | ||
|
||
private static String add(OnlineRadixSorterForIntegratedKeys<Integer> sorter, ArrayList<Integer> receivedItems, int v) { | ||
sorter.add(v, ()-> receivedItems.add(v)); | ||
private static String add(OnlineRadixSorterForIntegratedKeys<Integer> sorter, | ||
Map<Integer, DiagnosticTrackableCompletableFuture<String,Void>> m, | ||
ArrayList<Integer> receivedItems, int v) { | ||
var dcf = sorter.add(v, () -> receivedItems.add(v)); | ||
if (m != null) { m.put(v, dcf); } | ||
log.atInfo().setMessage(()->"after adding work... "+dcf).log(); | ||
return stringify(receivedItems.stream()); | ||
} | ||
|
||
@Test | ||
void testOnlineRadixSorter_inOrder() { | ||
var radixSorter = new OnlineRadixSorterForIntegratedKeys(1, i -> (int) i); | ||
Assertions.assertEquals("1", add(radixSorter, new ArrayList<Integer>(), 1)); | ||
Assertions.assertEquals("2", add(radixSorter, new ArrayList<Integer>(), 2)); | ||
Assertions.assertEquals("3", add(radixSorter, new ArrayList<Integer>(), 3)); | ||
Assertions.assertEquals("1", add(radixSorter, null, new ArrayList<Integer>(), 1)); | ||
Assertions.assertEquals("2", add(radixSorter, null, new ArrayList<Integer>(), 2)); | ||
Assertions.assertEquals("3", add(radixSorter, null, new ArrayList<Integer>(), 3)); | ||
} | ||
|
||
@Test | ||
void testOnlineRadixSorter_outOfOrder() { | ||
var radixSorter = new OnlineRadixSorterForIntegratedKeys(1, i->(int) i); | ||
var receiverList = new ArrayList<Integer>(); | ||
Assertions.assertEquals("", add(radixSorter, receiverList, 3)); | ||
Assertions.assertEquals("", add(radixSorter, receiverList, 4)); | ||
Assertions.assertEquals("1", add(radixSorter, receiverList, 1)); | ||
var dcfMap = new HashMap<Integer,DiagnosticTrackableCompletableFuture<String,Void>>(); | ||
Assertions.assertEquals("", add(radixSorter, dcfMap, receiverList, 3)); | ||
Assertions.assertEquals("", add(radixSorter, dcfMap, receiverList, 4)); | ||
Assertions.assertEquals("1", add(radixSorter, dcfMap, receiverList, 1)); | ||
log.atInfo().setMessage(()->"after adding work for '1'... dcf[3]=" + dcfMap.get(3)).log(); | ||
log.atInfo().setMessage(()->"after adding work for '1'... dcf[4]=" + dcfMap.get(4)).log(); | ||
receiverList.clear(); | ||
Assertions.assertEquals("2,3,4", add(radixSorter, receiverList, 2)); | ||
Assertions.assertEquals("2,3,4", add(radixSorter, dcfMap, receiverList, 2)); | ||
receiverList.clear(); | ||
Assertions.assertEquals("5", add(radixSorter, receiverList, 5)); | ||
Assertions.assertEquals("5", add(radixSorter, dcfMap, receiverList, 5)); | ||
receiverList.clear(); | ||
Assertions.assertEquals("", add(radixSorter, receiverList, 7)); | ||
Assertions.assertEquals("", add(radixSorter, dcfMap, receiverList, 7)); | ||
receiverList.clear(); | ||
} | ||
} |
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