Skip to content

Commit

Permalink
[BAEL-3463] - Big Queue (eugenp#8517)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris9408 authored and maibin committed Jan 13, 2020
1 parent 8530388 commit 210e4b0
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
15 changes: 15 additions & 0 deletions data-structures/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
<version>1.0.0-SNAPSHOT</version>
</parent>

<repositories>
<repository>
<id>github.release.repo</id>
<url>https://raw.github.com/bulldog2011/bulldog-repo/master/repo/releases/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.leansoft</groupId>
<artifactId>bigqueue</artifactId>
<version>0.7.0</version>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.baeldung.bigqueue;

import com.leansoft.bigqueue.BigQueueImpl;
import com.leansoft.bigqueue.IBigQueue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;

@RunWith(JUnit4.class)
public class BigQueueLiveTest {

private IBigQueue bigQueue;

@Before
public void setup() throws IOException {
String queueDir = System.getProperty("user.home");
String queueName = "baeldung-queue";
bigQueue = new BigQueueImpl(queueDir, queueName);
}

@After
public void emptyQueue() throws IOException {
bigQueue.removeAll();
bigQueue.gc();
bigQueue.close();
}

@Test
public void whenAddingRecords_ThenTheSizeIsCorrect() throws IOException {
for (int i = 1; i <= 100; i++) {
bigQueue.enqueue(String.valueOf(i).getBytes());
}

assertEquals(100, bigQueue.size());
}

@Test
public void whenAddingRecords_ThenTheyCanBeRetrieved() throws IOException {
bigQueue.enqueue(String.valueOf("new_record").getBytes());

String record = new String(bigQueue.dequeue());
assertEquals("new_record", record);
}

@Test
public void whenDequeueingRecords_ThenTheyAreConsumed() throws IOException {
for (int i = 1; i <= 100; i++) {
bigQueue.enqueue(String.valueOf(i).getBytes());
}
bigQueue.dequeue();

assertEquals(99, bigQueue.size());
}

@Test
public void whenPeekingRecords_ThenSizeDoesntChange() throws IOException {
for (int i = 1; i <= 100; i++) {
bigQueue.enqueue(String.valueOf(i).getBytes());
}
String firstRecord = new String(bigQueue.peek());

assertEquals("1", firstRecord);
assertEquals(100, bigQueue.size());
}

@Test
public void whenEmptyingTheQueue_ThenItSizeIs0() throws IOException {
for (int i = 1; i <= 100; i++) {
bigQueue.enqueue(String.valueOf(i).getBytes());
}
bigQueue.removeAll();

assertEquals(0, bigQueue.size());
}

}

0 comments on commit 210e4b0

Please sign in to comment.