View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2012-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.dynamo;
6   
7   import java.util.Iterator;
8   import org.apache.commons.lang3.RandomStringUtils;
9   import org.hamcrest.MatcherAssert;
10  import org.hamcrest.Matchers;
11  import org.junit.jupiter.api.Assumptions;
12  import org.junit.jupiter.api.BeforeEach;
13  import org.junit.jupiter.api.Test;
14  
15  /**
16   * Integration case for {@link AwsIterator}.
17   * @since 0.16.2
18   */
19  final class AwsIteratorITCase {
20  
21      @BeforeEach
22      void itTestCheck() {
23          Assumptions.assumeFalse(System.getProperty("failsafe.port", "").isEmpty());
24      }
25  
26      @Test
27      void iteratesItems() throws Exception {
28          final String name = RandomStringUtils.secure().nextAlphabetic(8);
29          final RegionMock mock = new RegionMock();
30          final Table tbl = mock.get(name).table(name);
31          tbl.put(
32              new Attributes()
33                  .with(mock.hash(), "test")
34                  .with(mock.range(), 1L)
35          );
36          MatcherAssert.assertThat(
37              "should has size 1",
38              tbl.frame(),
39              Matchers.hasSize(1)
40          );
41      }
42  
43      @Test
44      void iteratesItemsAndDeletes() throws Exception {
45          final String name = RandomStringUtils.secure().nextAlphabetic(8);
46          final RegionMock mock = new RegionMock();
47          final Table tbl = mock.get(name).table(name);
48          for (int idx = 0; idx < 6; ++idx) {
49              tbl.put(
50                  new Attributes()
51                      .with(mock.range(), 1L)
52                      .with(mock.hash(), String.format("i%d", idx))
53              );
54          }
55          final Iterator<Item> items = tbl.frame().iterator();
56          int cnt = 0;
57          while (items.hasNext()) {
58              items.next();
59              items.remove();
60              ++cnt;
61              if (cnt > 100) {
62                  throw new IllegalStateException("too many items");
63              }
64          }
65          MatcherAssert.assertThat(
66              "should has size 0",
67              tbl.frame(),
68              Matchers.hasSize(0)
69          );
70      }
71  
72  }