Skip to content

Commit 852e47b

Browse files
authored
Merge pull request #79 from eclipse/improvements-couchbase
Improvements couchbase
2 parents 98a8a88 + 492ebe7 commit 852e47b

File tree

3 files changed

+100
-9
lines changed

3 files changed

+100
-9
lines changed

couchbase-driver/src/main/java/org/jnosql/diana/couchbase/key/CouchbaseBucketManager.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.couchbase.client.java.Bucket;
1919
import com.couchbase.client.java.document.JsonDocument;
2020
import com.couchbase.client.java.document.json.JsonObject;
21+
import com.couchbase.client.java.error.DocumentDoesNotExistException;
2122
import org.jnosql.diana.api.Value;
2223
import org.jnosql.diana.api.key.BucketManager;
2324
import org.jnosql.diana.api.key.KeyValueEntity;
@@ -28,6 +29,7 @@
2829
import java.time.Duration;
2930
import java.util.Objects;
3031
import java.util.Optional;
32+
import java.util.logging.Logger;
3133

3234
import static java.util.Objects.requireNonNull;
3335
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -40,6 +42,8 @@
4042
*/
4143
public class CouchbaseBucketManager implements BucketManager {
4244

45+
private static final Logger LOGGER = Logger.getLogger(CouchbaseBucketManager.class.getName());
46+
4347
private static final Jsonb JSONB = JsonbBuilder.create();
4448

4549
private final Bucket bucket;
@@ -113,7 +117,11 @@ public <K> Iterable<Value> get(Iterable<K> keys) throws NullPointerException {
113117
@Override
114118
public <K> void remove(K key) throws NullPointerException {
115119
requireNonNull(key, "key is required");
116-
bucket.remove(key.toString());
120+
try {
121+
bucket.remove(key.toString());
122+
} catch (DocumentDoesNotExistException e) {
123+
LOGGER.info("Not found any document with the key " + key);
124+
}
117125
}
118126

119127
@Override

couchbase-driver/src/test/java/org/jnosql/diana/couchbase/key/CouchbaseBucketManagerTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.jnosql.diana.couchbase.CouchbaseUtil;
2222
import org.junit.jupiter.api.AfterAll;
2323
import org.junit.jupiter.api.BeforeEach;
24-
import org.junit.jupiter.api.Disabled;
2524
import org.junit.jupiter.api.Test;
2625

2726
import java.time.Duration;
@@ -96,26 +95,24 @@ public void shouldPutValues() {
9695
}
9796

9897
@Test
99-
@Disabled
10098
public void shouldPutValueTtl() throws InterruptedException {
10199

102100
keyValueEntityManager.put(KeyValueEntity.of(KEY_OTAVIO, userOtavio), Duration.ofSeconds(1L));
103101

104102
Optional<Value> otavio = keyValueEntityManager.get(KEY_OTAVIO);
105103
assertTrue(otavio.isPresent());
106-
Thread.sleep(5_000);
104+
Thread.sleep(2_000);
107105
otavio = keyValueEntityManager.get(KEY_OTAVIO);
108106
assertFalse(otavio.isPresent());
109107
}
110108

111109
@Test
112-
@Disabled
113110
public void shouldPutValuesTtl() throws InterruptedException {
114111

115112
keyValueEntityManager.put(singleton(KeyValueEntity.of(KEY_OTAVIO, userOtavio)), Duration.ofSeconds(1L));
116113
Optional<Value> otavio = keyValueEntityManager.get(KEY_OTAVIO);
117114
assertTrue(otavio.isPresent());
118-
Thread.sleep(5_000);
115+
Thread.sleep(2_000);
119116
otavio = keyValueEntityManager.get(KEY_OTAVIO);
120117
assertFalse(otavio.isPresent());
121118
}

couchbase-driver/src/test/java/org/jnosql/diana/couchbase/key/CouchbaseListTest.java

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@
2626
import java.math.BigDecimal;
2727
import java.util.List;
2828

29-
import static org.junit.jupiter.api.Assertions.*;
29+
import static java.util.Arrays.asList;
30+
import static org.hamcrest.MatcherAssert.assertThat;
31+
import static org.hamcrest.Matchers.contains;
32+
import static org.hamcrest.Matchers.containsInAnyOrder;
33+
import static org.junit.jupiter.api.Assertions.assertEquals;
34+
import static org.junit.jupiter.api.Assertions.assertFalse;
35+
import static org.junit.jupiter.api.Assertions.assertNotNull;
36+
import static org.junit.jupiter.api.Assertions.assertTrue;
3037

3138
public class CouchbaseListTest {
3239

@@ -70,10 +77,89 @@ public void shouldAddList() {
7077
}
7178

7279
@Test
73-
public void shouldRemoveList() {
74-
fruits.add(banana);
80+
public void shouldAddAllIterable() {
81+
fruits.addAll(asList(banana, waterMelon, orange, melon));
82+
assertThat(fruits, contains(banana, waterMelon, orange, melon));
7583
}
7684

85+
@Test
86+
public void shouldAddAllIterableWithIndex() {
87+
fruits.addAll(asList(orange, melon));
88+
fruits.addAll(1, asList(banana, waterMelon));
89+
assertThat(fruits, contains(orange, banana, waterMelon, melon));
90+
}
91+
92+
@Test
93+
public void shouldAddWithIndex() {
94+
fruits.addAll(asList(banana, waterMelon));
95+
fruits.add(0, orange);
96+
assertThat(fruits, contains(orange, banana, waterMelon));
97+
}
98+
99+
@Test
100+
public void shouldRemove() {
101+
fruits.addAll(asList(banana, waterMelon));
102+
fruits.remove(banana);
103+
assertTrue(fruits.size() == 1);
104+
assertEquals(fruits.get(0), waterMelon);
105+
}
106+
107+
@Test
108+
public void shouldRemoveWithIndex() {
109+
fruits.addAll(asList(banana, waterMelon));
110+
fruits.remove(1);
111+
assertTrue(fruits.size() == 1);
112+
assertEquals(fruits.get(0), banana);
113+
}
114+
115+
@Test
116+
public void shouldRemoveAll() {
117+
fruits.addAll(asList(banana, waterMelon, orange, melon));
118+
fruits.removeAll(asList(banana, melon));
119+
assertTrue(fruits.size() == 2);
120+
assertThat(fruits, containsInAnyOrder(waterMelon, orange));
121+
}
122+
123+
@Test
124+
public void shouldContainsValue() {
125+
fruits.addAll(asList(banana, waterMelon));
126+
assertTrue(fruits.contains(waterMelon));
127+
}
128+
129+
@Test
130+
public void shouldContainsAllValues() {
131+
fruits.addAll(asList(banana, waterMelon));
132+
assertTrue(fruits.containsAll(asList(waterMelon, banana)));
133+
}
134+
135+
@Test
136+
public void shouldReturnIndexOf() {
137+
fruits.addAll(asList(banana, waterMelon, banana));
138+
assertEquals(0, fruits.indexOf(banana));
139+
}
140+
141+
@Test
142+
public void shouldReturnLstIndexOf() {
143+
fruits.addAll(asList(banana, waterMelon, banana));
144+
assertEquals(2, fruits.lastIndexOf(banana));
145+
}
146+
147+
@Test
148+
public void shouldSetValue() {
149+
fruits.addAll(asList(banana, waterMelon));
150+
assertEquals(fruits.get(1), waterMelon);
151+
fruits.set(1, orange);
152+
assertTrue(fruits.size() == 2);
153+
assertEquals(fruits.get(1), orange);
154+
}
155+
156+
@Test
157+
public void shouldReturnSubList() {
158+
fruits.addAll(asList(banana, waterMelon, orange, melon));
159+
List<ProductCart> subList = fruits.subList(1, 3);
160+
assertTrue(subList.size() == 2);
161+
assertThat(subList, contains(waterMelon, orange));
162+
}
77163

78164
@AfterEach
79165
public void end() {

0 commit comments

Comments
 (0)