Skip to content

Commit

Permalink
6.1.8 version
Browse files Browse the repository at this point in the history
a couple of test
  • Loading branch information
oscar-besga-panel committed Dec 25, 2023
1 parent a275bf1 commit 22a6eb9
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 51 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ It's intended to make possible distributes locking and synchronization, share da

All classes have tests, unit and functional ones.
You can test the latter ones by activating them and configuring your own redis server, to test that all the classes work properly in theory and practice.
There are **more than 600 working tests**, so the code is pretty secure.
There are **more than 630 working tests**, so the code is pretty secure.


**See the [wiki](https://github.com/oscar-besga-panel/JedisExtraUtils/wiki) for more documentation**
Expand Down Expand Up @@ -169,6 +169,20 @@ A list of elements that every request gets the next element, and if it reaches t
Any call gives only one result.
It can be used with an iterator, but because the list cycles it can lead to an infinite loop, so be aware.

### Rate Limiter

It limits the number of operations/calls/actions you can have
There are two implementations
* ThrottlingRateLimiter, based on request/time limitation
* BucketRateLimiter, based on bucket algorithm, which has a number of autorefilling permits to give to request

### Others
* StreamMessageSystem is a sender/reciever messages from a stream, with a AL-LEAST-ONCE policy that doesn't skip messages
* SimplePubSub: a simple pub/sub that only consumes messages via a BiConsumer function
* ScriptEvalSha1: to evaluate a reuse LUA scripts
* UniversalReader: (not redis, local) read a file, resource or value; one after another if not present.
* Others....


See [wiki](https://github.com/oscar-besga-panel/JedisExtraUtils/wiki/CycleData) for more information

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
projectVersion=6.1.2
projectVersion=6.1.8
#javaVersion=JavaVersion.VERSION_11
javaVersion=11

Expand All @@ -8,7 +8,7 @@ shadowVersion=7.1.2
# https://mvnrepository.com/artifact/redis.clients/jedis/5.1.0
jedisVersion=5.1.0
# https://mvnrepository.com/artifact/org.javassist/javassist
javassistVersion=3.29.2-GA
javassistVersion=3.30.1-GA
# https://mvnrepository.com/artifact/org.slf4j/slf4j-api
slf4jVersion=1.7.36

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

import static org.oba.jedis.extra.utils.lock.UniqueTokenValueGenerator.generateUniqueTokenValue;

/**
* A lock that checks if the locks have been freed with a streaming mechanism
* This avoid polling and optimizes connection usage
*/
public class NotificationLock implements IJedisLock, MessageListener {

private static final Logger LOGGER = LoggerFactory.getLogger(NotificationLock.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package org.oba.jedis.extra.utils.streamMessageSystem;

/**
* Interface to listen to a message from a stream
*/
public interface MessageListener {

/**
* Recieve a message
* @param message Data recieved from stream
*/
void onMessage(String message);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ScriptHolder implements JedisPoolUser {
private final Map<String, ScriptEvalSha1> scriptMap = new HashMap<>();


static ScriptHolder generateHolderForJedisExtraUtils(JedisPool jedisPool) {
public static ScriptHolder generateHolderForJedisExtraUtils(JedisPool jedisPool) {
ScriptHolder scriptHolder = new ScriptHolder(jedisPool);
scriptHolder.addScriptWithResourceAndFile(BucketRateLimiter.SCRIPT_NAME, BucketRateLimiter.FILE_PATH);
scriptHolder.addScriptWithResourceAndFile(CycleData.SCRIPT_NAME, CycleData.FILE_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.oba.jedis.extra.utils.iterators.MockOfJedis.unitTestEnabled;

public class HscanIterableTest {
Expand Down Expand Up @@ -76,6 +68,8 @@ public void iteratorEmptyTest() {
assertNotNull(iterator);
assertTrue(sb.length() == 0);
assertTrue(num == 0);
assertNotNull(hscanIterable.getJedisPool());
assertEquals(hscanitName, hscanIterable.getName());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.oba.jedis.extra.utils.iterators.MockOfJedis.unitTestEnabled;

public class ScanIterableTest {
Expand Down Expand Up @@ -75,6 +72,7 @@ public void iteratorEmptyTest() {
assertNotNull(iterator);
assertTrue(sb.length() == 0);
assertTrue(num == 0);
assertNotNull(scanIterable.getJedisPool());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.oba.jedis.extra.utils.iterators.MockOfJedis.unitTestEnabled;

public class SscanIterableTest {
Expand Down Expand Up @@ -74,6 +70,8 @@ public void iteratorEmptyTest() {
assertNotNull(iterator);
assertTrue(sb.length() == 0);
assertTrue(num == 0);
assertNotNull(sscanIterable.getJedisPool());
assertEquals(sscanitName, sscanIterable.getName());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.oba.jedis.extra.utils.iterators.MockOfJedis.unitTestEnabled;

public class ZscanIterableTest {
Expand Down Expand Up @@ -81,6 +77,8 @@ public void iteratorEmptyTest() {
assertNotNull(iterator);
assertTrue(sb.length() == 0);
assertTrue(num == 0);
assertNotNull(zscanIterable.getJedisPool());
assertEquals(zscanitName, zscanIterable.getName());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,10 @@
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

public class FunctionalHscanIterableTest {

Expand Down Expand Up @@ -82,6 +74,8 @@ public void iteratorEmptyTest() {
assertNotNull(iterator);
assertTrue(sb.length() == 0);
assertTrue(num == 0);
assertNotNull(hscanIterable.getJedisPool());
assertEquals(hscanitName, hscanIterable.getName());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

public class FunctionalScanIterableTest {

Expand Down Expand Up @@ -76,6 +73,7 @@ public void iteratorEmptyTest() {
assertNotNull(iterator);
assertTrue(sb.length() == 0);
assertTrue(num == 0);
assertNotNull(scanIterable.getJedisPool());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

public class FunctionalSscanIterableTest {

Expand Down Expand Up @@ -76,6 +73,8 @@ public void iteratorEmptyTest() {
assertNotNull(iterator);
assertTrue(sb.length() == 0);
assertTrue(num == 0);
assertNotNull(sscanIterable.getJedisPool());
assertEquals(sscanitName, sscanIterable.getName());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

public class FunctionalZscanIterableTest {

Expand Down Expand Up @@ -87,6 +83,8 @@ public void iteratorEmptyTest() {
assertNotNull(iterator);
assertTrue(sb.length() == 0);
assertTrue(num == 0);
assertNotNull(zscanIterable.getJedisPool());
assertEquals(zscanitName, zscanIterable.getName());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.oba.jedis.extra.utils.collections.JedisList;
import org.oba.jedis.extra.utils.cycle.CycleData;
import org.oba.jedis.extra.utils.interruptinglocks.JedisLock;
import org.oba.jedis.extra.utils.rateLimiter.BucketRateLimiter;
import org.oba.jedis.extra.utils.semaphore.JedisSemaphore;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -36,6 +41,17 @@ public void after() throws IOException {
mockOfJedis.clearData();
}

@Test
public void generateHolderForJedisExtraUtilsTest() {
ScriptHolder holder = ScriptHolder.generateHolderForJedisExtraUtils(mockOfJedis.getJedisPool());
assertNotNull(holder.getScript(BucketRateLimiter.SCRIPT_NAME));
assertNotNull(holder.getScript(CycleData.SCRIPT_NAME));
assertNotNull(holder.getScript(JedisList.SCRIPT_NAME_INDEX_OF));
assertNotNull(holder.getScript(JedisList.SCRIPT_NAME_LAST_INDEX_OF));
assertNotNull(holder.getScript(JedisLock.SCRIPT_NAME));
assertNotNull(holder.getScript(JedisSemaphore.SCRIPT_NAME));
}

@Test
public void addTest() {
ScriptEvalSha1 scriptEvalSha1 = new ScriptEvalSha1(mockOfJedis.getJedisPool(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.oba.jedis.extra.utils.collections.JedisList;
import org.oba.jedis.extra.utils.cycle.CycleData;
import org.oba.jedis.extra.utils.interruptinglocks.JedisLock;
import org.oba.jedis.extra.utils.rateLimiter.BucketRateLimiter;
import org.oba.jedis.extra.utils.semaphore.JedisSemaphore;
import org.oba.jedis.extra.utils.test.JedisTestFactory;
import org.oba.jedis.extra.utils.utils.ScriptEvalSha1;
import org.oba.jedis.extra.utils.utils.ScriptHolder;
Expand Down Expand Up @@ -46,6 +51,17 @@ public void after() throws IOException {
}
}

@Test
public void generateHolderForJedisExtraUtilsTest() {
ScriptHolder holder = ScriptHolder.generateHolderForJedisExtraUtils(jedisPool);
assertNotNull(holder.getScript(BucketRateLimiter.SCRIPT_NAME));
assertNotNull(holder.getScript(CycleData.SCRIPT_NAME));
assertNotNull(holder.getScript(JedisList.SCRIPT_NAME_INDEX_OF));
assertNotNull(holder.getScript(JedisList.SCRIPT_NAME_LAST_INDEX_OF));
assertNotNull(holder.getScript(JedisLock.SCRIPT_NAME));
assertNotNull(holder.getScript(JedisSemaphore.SCRIPT_NAME));
}

@Test
public void addTest() {
ScriptEvalSha1 scriptEvalSha1 = new ScriptEvalSha1(jedisPool,
Expand Down

0 comments on commit 22a6eb9

Please sign in to comment.