-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-4899 Introduce MapDB3 backed queue to the MapDb3CollectionFactory
- Loading branch information
1 parent
3996cd8
commit 85dcb36
Showing
2 changed files
with
210 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...src/test/java/org/eclipse/rdf4j/collection/factory/mapdb/MapDb3CollectionFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eclipse RDF4J contributors. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*******************************************************************************/ | ||
package org.eclipse.rdf4j.collection.factory.mapdb; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
import java.util.Queue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class MapDb3CollectionFactoryTest { | ||
|
||
@Test | ||
void queuOfferAnd() { | ||
try (MapDb3CollectionFactory mapDb3CollectionFactory = new MapDb3CollectionFactory(1)) { | ||
Queue<String> q = mapDb3CollectionFactory.createQueue(); | ||
int size = 1024; | ||
for (int i = 0; i < size; i++) { | ||
assertTrue(q.offer(Integer.toString(i))); | ||
} | ||
assertEquals(size, q.size()); | ||
for (int i = 0; i < size; i++) { | ||
String p = q.peek(); | ||
assertEquals(p, Integer.toString(i)); | ||
String p2 = q.peek(); | ||
assertEquals(p2, Integer.toString(i)); | ||
String s = q.poll(); | ||
assertEquals(s, Integer.toString(i)); | ||
} | ||
assertEquals(0, q.size()); | ||
} | ||
} | ||
|
||
@Test | ||
void iterator() { | ||
try (MapDb3CollectionFactory mapDb3CollectionFactory = new MapDb3CollectionFactory(1)) { | ||
Queue<String> q = mapDb3CollectionFactory.createQueue(); | ||
int size = 1024; | ||
for (int i = 0; i < size; i++) { | ||
assertTrue(q.offer(Integer.toString(i))); | ||
} | ||
assertEquals(size, q.size()); | ||
Iterator<String> iter = q.iterator(); | ||
for (int i = 0; i < size; i++) { | ||
assertTrue(iter.hasNext()); | ||
assertEquals(iter.next(), Integer.toString(i)); | ||
} | ||
assertFalse(iter.hasNext()); | ||
assertEquals(size, q.size()); | ||
try { | ||
iter.next(); | ||
fail(); | ||
} catch (NoSuchElementException e) { | ||
assertNotNull(e); | ||
} | ||
} | ||
} | ||
} |