1 /*
2 * Copyright (c) 2012-2023, jcabi.com
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met: 1) Redistributions of source code must retain the above
8 * copyright notice, this list of conditions and the following
9 * disclaimer. 2) Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution. 3) Neither the name of the jcabi.com nor
13 * the names of its contributors may be used to endorse or promote
14 * products derived from this software without specific prior written
15 * permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
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 * Integration case for {@link AwsIterator}.
43 * @since 0.16.2
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 }