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 package com.jcabi.dynamo;
31
32 import com.jcabi.aspects.Tv;
33 import java.util.Iterator;
34 import org.apache.commons.lang3.RandomStringUtils;
35 import org.hamcrest.MatcherAssert;
36 import org.hamcrest.Matchers;
37 import org.junit.jupiter.api.Assumptions;
38 import org.junit.jupiter.api.BeforeEach;
39 import org.junit.jupiter.api.Test;
40
41
42
43
44
45 final class AwsIteratorITCase {
46
47 @BeforeEach
48 void itTestCheck() {
49 Assumptions.assumeFalse(System.getProperty("failsafe.port", "").isEmpty());
50 }
51
52 @Test
53 void iteratesItems() throws Exception {
54 final String name = RandomStringUtils.randomAlphabetic(Tv.EIGHT);
55 final RegionMock mock = new RegionMock();
56 final Table tbl = mock.get(name).table(name);
57 tbl.put(
58 new Attributes()
59 .with(mock.hash(), "test")
60 .with(mock.range(), 1L)
61 );
62 MatcherAssert.assertThat(
63 tbl.frame(),
64 Matchers.hasSize(1)
65 );
66 }
67
68 @Test
69 void iteratesItemsAndDeletes() throws Exception {
70 final String name = RandomStringUtils.randomAlphabetic(Tv.EIGHT);
71 final RegionMock mock = new RegionMock();
72 final Table tbl = mock.get(name).table(name);
73 final Attributes attrs = new Attributes().with(mock.range(), 1L);
74 for (int idx = 0; idx < Tv.SIX; ++idx) {
75 tbl.put(attrs.with(mock.hash(), String.format("i%d", idx)));
76 }
77 final Iterator<Item> items = tbl.frame().iterator();
78 int cnt = 0;
79 while (items.hasNext()) {
80 items.next();
81 items.remove();
82 ++cnt;
83 if (cnt > Tv.HUNDRED) {
84 throw new IllegalStateException("too many items");
85 }
86 }
87 MatcherAssert.assertThat(
88 tbl.frame(),
89 Matchers.hasSize(0)
90 );
91 }
92
93 }