Skip to content

Commit 210e4b0

Browse files
chris9408maibin
authored andcommitted
[BAEL-3463] - Big Queue (eugenp#8517)
1 parent 8530388 commit 210e4b0

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

data-structures/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212
<version>1.0.0-SNAPSHOT</version>
1313
</parent>
1414

15+
<repositories>
16+
<repository>
17+
<id>github.release.repo</id>
18+
<url>https://raw.github.com/bulldog2011/bulldog-repo/master/repo/releases/</url>
19+
</repository>
20+
</repositories>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>com.leansoft</groupId>
25+
<artifactId>bigqueue</artifactId>
26+
<version>0.7.0</version>
27+
</dependency>
28+
</dependencies>
29+
1530
<build>
1631
<pluginManagement>
1732
<plugins>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.baeldung.bigqueue;
2+
3+
import com.leansoft.bigqueue.BigQueueImpl;
4+
import com.leansoft.bigqueue.IBigQueue;
5+
import org.junit.After;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
import org.junit.runners.JUnit4;
10+
11+
import java.io.IOException;
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
15+
@RunWith(JUnit4.class)
16+
public class BigQueueLiveTest {
17+
18+
private IBigQueue bigQueue;
19+
20+
@Before
21+
public void setup() throws IOException {
22+
String queueDir = System.getProperty("user.home");
23+
String queueName = "baeldung-queue";
24+
bigQueue = new BigQueueImpl(queueDir, queueName);
25+
}
26+
27+
@After
28+
public void emptyQueue() throws IOException {
29+
bigQueue.removeAll();
30+
bigQueue.gc();
31+
bigQueue.close();
32+
}
33+
34+
@Test
35+
public void whenAddingRecords_ThenTheSizeIsCorrect() throws IOException {
36+
for (int i = 1; i <= 100; i++) {
37+
bigQueue.enqueue(String.valueOf(i).getBytes());
38+
}
39+
40+
assertEquals(100, bigQueue.size());
41+
}
42+
43+
@Test
44+
public void whenAddingRecords_ThenTheyCanBeRetrieved() throws IOException {
45+
bigQueue.enqueue(String.valueOf("new_record").getBytes());
46+
47+
String record = new String(bigQueue.dequeue());
48+
assertEquals("new_record", record);
49+
}
50+
51+
@Test
52+
public void whenDequeueingRecords_ThenTheyAreConsumed() throws IOException {
53+
for (int i = 1; i <= 100; i++) {
54+
bigQueue.enqueue(String.valueOf(i).getBytes());
55+
}
56+
bigQueue.dequeue();
57+
58+
assertEquals(99, bigQueue.size());
59+
}
60+
61+
@Test
62+
public void whenPeekingRecords_ThenSizeDoesntChange() throws IOException {
63+
for (int i = 1; i <= 100; i++) {
64+
bigQueue.enqueue(String.valueOf(i).getBytes());
65+
}
66+
String firstRecord = new String(bigQueue.peek());
67+
68+
assertEquals("1", firstRecord);
69+
assertEquals(100, bigQueue.size());
70+
}
71+
72+
@Test
73+
public void whenEmptyingTheQueue_ThenItSizeIs0() throws IOException {
74+
for (int i = 1; i <= 100; i++) {
75+
bigQueue.enqueue(String.valueOf(i).getBytes());
76+
}
77+
bigQueue.removeAll();
78+
79+
assertEquals(0, bigQueue.size());
80+
}
81+
82+
}

0 commit comments

Comments
 (0)