-
Notifications
You must be signed in to change notification settings - Fork 4
/
MusicCatalogModulesTest.java
79 lines (66 loc) · 3.94 KB
/
MusicCatalogModulesTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package rama.gallery;
import com.rpl.rama.ops.Ops;
import org.junit.Test;
import com.rpl.rama.*;
import com.rpl.rama.test.*;
import rama.gallery.migrations.MusicCatalogModules;
import rama.gallery.migrations.data.Album;
import rama.gallery.migrations.data.Song;
import java.util.*;
import static org.junit.Assert.*;
public class MusicCatalogModulesTest {
@Test
public void test() throws Exception {
// InProcessCluster simulates a full Rama cluster in-process and is an ideal environment for experimentation and
// unit-testing.
try(InProcessCluster ipc = InProcessCluster.create()) {
// First we construct our initial module instance and deploy it.
MusicCatalogModules.ModuleInstanceA moduleInstanceA = new MusicCatalogModules.ModuleInstanceA();
ipc.launchModule(moduleInstanceA, new LaunchConfig(4, 2));
// We'll use our module's name to fetch handles on its depots and PStates.
String moduleName = moduleInstanceA.getModuleName();
// Client usage of IPC is identical to using a real cluster. Depot, PState, and query topology clients are fetched
// by referencing the module name along with the variable used to identify the depot/PState/query within the module.
Depot albumsDepot = ipc.clusterDepot(moduleName, "*albumsDepot");
PState albums = ipc.clusterPState(moduleName, "$$albums");
// Now we construct an Album and append it to the depot.
Album f1Trillion = new Album(
"Post Malone",
"F-1 Trillion",
Collections.singletonList("Have The Heart ft. Dolly Parton"));
albumsDepot.append(f1Trillion);
// We wait for our microbatch to process the album.
ipc.waitForMicrobatchProcessedCount(moduleName, "albums", 1);
// Once processed, we expect that our album will be indexed in the PState.
assertEquals((Object)1, albums.selectOne(Path.key("Post Malone").view(Ops.SIZE)));
assertEquals("F-1 Trillion", albums.selectOne(Path.key("Post Malone", "F-1 Trillion", "name")));
assertEquals("Have The Heart ft. Dolly Parton",
albums.selectOne(Path.key("Post Malone", "F-1 Trillion", "songs")
.first()));
// Now we construct the next iteration of our module and deploy it via module update.
MusicCatalogModules.ModuleInstanceB moduleInstanceB = new MusicCatalogModules.ModuleInstanceB();
ipc.updateModule(moduleInstanceB);
// We expect that albums previously appended will now have the new Song structure
assertEquals("Have The Heart",
albums.selectOne(Path.key("Post Malone", "F-1 Trillion", "songs")
.first().view((Song s) -> s.name)));
assertEquals("Dolly Parton",
albums.selectOne(Path.key("Post Malone", "F-1 Trillion", "songs")
.first().view((Song s) -> s.featuredArtists).first()));
// Albums newly appended will go through the new topology code, and have their Songs parsed before indexing.
Album channelOrange = new Album(
"Frank Ocean",
"Channel Orange",
Collections.singletonList("White feat. John Mayer"));
albumsDepot.append(channelOrange);
// We wait for our microbatch to process the album.
ipc.waitForMicrobatchProcessedCount(moduleName, "albums", 2);
assertEquals("White",
albums.selectOne(Path.key("Frank Ocean", "Channel Orange", "songs")
.first().view((Song s) -> s.name)));
assertEquals("John Mayer",
albums.selectOne(Path.key("Frank Ocean", "Channel Orange", "songs")
.first().view((Song s) -> s.featuredArtists).first()));
}
}
}