Search in sources :

Example 1 with QueueWorker

use of dk.dbc.pgqueue.consumer.QueueWorker in project solr-document-store by DBCDK.

the class QueueJobIT method testStoreRetrieve.

@Test(timeout = 5000L)
public void testStoreRetrieve() throws Exception {
    System.out.println("store-retrieve");
    QueueJob job1 = new QueueJob(888888, "clazzifier", "12345678");
    QueueJob job2 = new QueueJob(888888, "clazzifier", "87654321", 1000);
    try (Connection connection = dataSource.getConnection()) {
        PreparedQueueSupplier<QueueJob> supplier = QUEUE_SUPPLIER.preparedSupplier(connection);
        supplier.enqueue(QUEUE, job1);
        supplier.enqueue(QUEUE, job2);
        BlockingDeque<QueueJob> list = new LinkedBlockingDeque<>();
        QueueWorker worker = QueueWorker.builder().consume(QUEUE).dataSource(dataSource).build(QueueJob.STORAGE_ABSTRACTION, (JobConsumer<QueueJob>) (Connection connection1, QueueJob job, JobMetaData metaData) -> {
            list.add(job);
        });
        worker.start();
        QueueJob actual1 = list.pollFirst(5, TimeUnit.SECONDS);
        QueueJob actual2 = list.pollFirst(5, TimeUnit.SECONDS);
        worker.stop();
        assertEquals(job1.toString(), actual1.toString());
        assertEquals(job2.toString(), actual2.toString());
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) JobMetaData(dk.dbc.pgqueue.consumer.JobMetaData) Connection(java.sql.Connection) QueueWorker(dk.dbc.pgqueue.consumer.QueueWorker) Test(org.junit.Test)

Aggregations

JobMetaData (dk.dbc.pgqueue.consumer.JobMetaData)1 QueueWorker (dk.dbc.pgqueue.consumer.QueueWorker)1 Connection (java.sql.Connection)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 Test (org.junit.Test)1