1
2
3
4
5 package com.jcabi.dynamo;
6
7 import org.apache.commons.lang3.RandomStringUtils;
8 import org.hamcrest.MatcherAssert;
9 import org.hamcrest.Matchers;
10 import org.junit.jupiter.api.Assumptions;
11 import org.junit.jupiter.api.BeforeEach;
12 import org.junit.jupiter.api.Test;
13
14
15
16
17
18 final class AwsFrameITCase {
19
20 @BeforeEach
21 void itTestCheck() {
22 Assumptions.assumeFalse(System.getProperty("failsafe.port", "").isEmpty());
23 }
24
25 @Test
26 void calculatesSizeWithScanLimitOne() throws Exception {
27 final String name = RandomStringUtils.secure().nextAlphabetic(8);
28 final RegionMock mock = new RegionMock();
29 final Table tbl = mock.get(name).table(name);
30 final String hash = RandomStringUtils.secure().nextAlphabetic(8);
31 for (int idx = 0; idx < 10; ++idx) {
32 tbl.put(
33 new Attributes()
34 .with(mock.hash(), hash)
35 .with(mock.range(), idx)
36 );
37 }
38 MatcherAssert.assertThat(
39 "should equal to 10",
40 tbl.frame()
41 .through(new ScanValve().withLimit(1))
42 .size(),
43 Matchers.equalTo(10)
44 );
45 }
46
47 @Test
48 void checksNotEmptyWithScanLimitOne() throws Exception {
49 final String name = RandomStringUtils.secure().nextAlphabetic(8);
50 final RegionMock mock = new RegionMock();
51 final Table tbl = mock.get(name).table(name);
52 final String hash = RandomStringUtils.secure().nextAlphabetic(8);
53 tbl.put(
54 new Attributes()
55 .with(mock.hash(), hash)
56 .with(mock.range(), 0)
57 );
58 MatcherAssert.assertThat(
59 "should equal to false",
60 tbl.frame()
61 .through(new ScanValve().withLimit(1))
62 .isEmpty(),
63 Matchers.equalTo(false)
64 );
65 }
66
67 @Test
68 void calculatesSizeWithScanLimitHundred() throws Exception {
69 final String name = RandomStringUtils.secure().nextAlphabetic(8);
70 final RegionMock mock = new RegionMock();
71 final Table tbl = mock.get(name).table(name);
72 final String hash = RandomStringUtils.secure().nextAlphabetic(8);
73 for (int idx = 0; idx < 10; ++idx) {
74 tbl.put(
75 new Attributes()
76 .with(mock.hash(), hash)
77 .with(mock.range(), idx)
78 );
79 }
80 MatcherAssert.assertThat(
81 "should equal to 10",
82 tbl.frame()
83 .through(new ScanValve().withLimit(100))
84 .size(),
85 Matchers.equalTo(10)
86 );
87 }
88
89 @Test
90 void calculatesSizeWithQueryLimitOne() throws Exception {
91 final String name = RandomStringUtils.secure().nextAlphabetic(8);
92 final RegionMock mock = new RegionMock();
93 final Table tbl = mock.get(name).table(name);
94 final String hash = RandomStringUtils.secure().nextAlphabetic(8);
95 for (int idx = 0; idx < 10; ++idx) {
96 tbl.put(
97 new Attributes()
98 .with(mock.hash(), hash)
99 .with(mock.range(), idx)
100 );
101 }
102 MatcherAssert.assertThat(
103 "should equal to 10",
104 tbl.frame()
105 .through(new QueryValve().withLimit(1))
106 .where(mock.hash(), hash)
107 .size(),
108 Matchers.equalTo(10)
109 );
110 }
111
112 @Test
113 void calculatesSizeWithQueryLimitHundred() throws Exception {
114 final String name = RandomStringUtils.secure().nextAlphabetic(8);
115 final RegionMock mock = new RegionMock();
116 final Table tbl = mock.get(name).table(name);
117 final String hash = RandomStringUtils.secure().nextAlphabetic(8);
118 for (int idx = 0; idx < 10; ++idx) {
119 tbl.put(
120 new Attributes()
121 .with(mock.hash(), hash)
122 .with(mock.range(), idx)
123 );
124 }
125 MatcherAssert.assertThat(
126 "should equal to 10",
127 tbl.frame()
128 .through(new QueryValve().withLimit(100))
129 .where(mock.hash(), hash)
130 .size(),
131 Matchers.equalTo(10)
132 );
133 }
134
135 }