forked from SkipLabs/skip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestLazy.sk
More file actions
117 lines (103 loc) · 3.03 KB
/
Copy pathTestLazy.sk
File metadata and controls
117 lines (103 loc) · 3.03 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
module SKFSTest;
fun testLazy(): mutable SKFS.Context {
context = SKFS.run(context ~> {
dirInput = context.mkdir(
SKFS.IntFile::fromFile,
SKFS.DirName::create("/input/"),
Array[(SKFS.IID(0), SKFS.IntFile(23))],
);
dirInput2 = context.mkdir(
SKFS.IntFile::fromFile,
SKFS.DirName::create("/input2/"),
Array[(SKFS.IID(0), SKFS.IntFile(44))],
);
dir1 = SKFS.LHandle::create(
SKFS.IntFile::fromFile,
context,
SKFS.DirName::create("/lazy1/"),
(context, _self, x) ~> {
Array[
SKFS.IntFile(
x match {
| SKFS.IID(v) ->
dirInput.getArray(context, SKFS.IID(0))[0].value + v
| _ -> error()
},
),
]
},
);
dir2 = SKFS.LHandle::create(
SKFS.IntFile::fromFile,
context,
SKFS.DirName::create("/lazy2/"),
(context, _self, key) ~> {
Array[SKFS.IntFile(dir1.getArray(context, key)[0].value)]
},
);
adir1 = SKFS.LHandle::createAsync(
SKFS.IntFile::fromFile,
context,
SKFS.DirName::create("/alazy1/"),
(context, _self, x) ~> {
Some(
Array[
SKFS.IntFile(
x match {
| SKFS.IID(v) ->
dirInput.getArray(context, SKFS.IID(0))[0].value + v
| _ -> error()
},
),
],
)
},
);
_adir2 = SKFS.LHandle::createAsync(
SKFS.IntFile::fromFile,
context,
SKFS.DirName::create("/alazy2/"),
(context, _self, key) ~> {
arr = adir1.getArrayAsync(context, key);
if (arr.size() == 0) None() else Some(Array[SKFS.IntFile(arr[0].value)])
},
);
_dir3 = dirInput2.contextWriterKeyMap(
SKFS.IntFile::fromFile,
context,
SKFS.DirName::create("/eager/"),
(context, writer, key, _) ~> {
writer.write(key, dir2.getArray(context, key)[0]);
},
)
});
input = SKFS.DirName::create("/input/");
dir2 = SKFS.DirName::create("/lazy2/");
adir2 = SKFS.DirName::create("/alazy2/");
dir3 = SKFS.DirName::create("/eager/");
expectEq("Async Lazy basic", Array<SKFS.File>[], () ->
getLazyData(context, adir2, SKFS.IID(0), true)
);
_ = context.updateWithStatus(0);
expectEq("Async Lazy basic with interruption", Array<SKFS.File>[], () ->
getLazyData(context, adir2, SKFS.IID(0), true)
);
_ = context.updateWithStatus(30);
expectEq(
"Async Lazy basic without interruption",
Array<SKFS.File>[SKFS.IntFile(23)],
() -> getLazyData(context, adir2, SKFS.IID(0), true),
);
expectEq("Lazy basic", Array<SKFS.File>[SKFS.IntFile(23)], () ->
getData(context, dir2, SKFS.IID(0))
);
write(context, input, SKFS.IID(0), Array[SKFS.IntFile(22)]);
context.update();
expectEq("Lazy after update", Array<SKFS.File>[SKFS.IntFile(22)], () ->
getData(context, dir2, SKFS.IID(0))
);
expectEq("Eeager after update", Array<SKFS.File>[SKFS.IntFile(22)], () ->
getData(context, dir3, SKFS.IID(0))
);
context
}