Skip to content

Commit

Permalink
Release 6.0.0
Browse files Browse the repository at this point in the history
update jedis to 5.0.2
fix tests
  • Loading branch information
oscar-besga-panel committed Nov 1, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 70815a1 commit e381bb7
Showing 18 changed files with 144 additions and 263 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -85,6 +85,7 @@ Also, you will find a little Groovy and a docker composer to setup a testing red

| Library version | Jedis version | JDK Version |
|-----------------|---------------|-------------|
| 6.0.0 | 5.0.X | JDK11 |
| 5.3.0 | 4.4.X | JDK11 |


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

# https://github.com/johnrengelman/shadow
shadowVersion=7.1.2

# https://mvnrepository.com/artifact/redis.clients/jedis/4.4.3
jedisVersion=4.4.3
jedisVersion=5.0.2
# https://mvnrepository.com/artifact/org.javassist/javassist
javassistVersion=3.29.2-GA
# https://mvnrepository.com/artifact/org.slf4j/slf4j-api
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import static org.oba.jedis.extra.utils.test.TestingUtils.extractSetParamsExpireTimePX;
import static org.oba.jedis.extra.utils.test.TestingUtils.isSetParamsNX;

/**
* Mock of jedis methods used by the lock
@@ -171,7 +173,7 @@ synchronized String mockSet(final String key, String value, SetParams setParams)
}
if (insert) {
data.put(key, value);
Long expireTime = getExpireTimePX(setParams);
Long expireTime = extractSetParamsExpireTimePX(setParams);
if (expireTime != null){
timer.schedule(TTL.wrapTTL(() -> data.remove(key)),expireTime);
}
@@ -257,21 +259,6 @@ synchronized void put(String key, String element) {
data.put(key, element);
}

boolean isSetParamsNX(SetParams setParams) {
boolean result = false;
for(byte[] b: setParams.getByteParams()){
String s = new String(b);
if ("nx".equalsIgnoreCase(s)){
result = true;
}
}
return result;
}

Long getExpireTimePX(SetParams setParams) {
return setParams.getParam("px");
}

public static String extractPatternFromScanParams(ScanParams scanParams) {
String pattern = scanParams.match();
if (pattern.equals("*")) {
@@ -293,6 +280,4 @@ static String[] fromObjectArray(Object[] data){
return result;
}



}
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@
import java.util.List;

import static org.junit.Assert.*;
import static org.oba.jedis.extra.utils.test.TestingUtils.extractSetParamsExpireTimePX;
import static org.oba.jedis.extra.utils.test.TestingUtils.isSetParamsNX;

@RunWith(PowerMockRunner.class)
@PrepareForTest({Transaction.class, TransactionBase.class })
@@ -41,20 +43,20 @@ public void tearDown() {
@Test
public void testParams() {
SetParams sp1 = new SetParams();
boolean t11 = mockOfJedisForSimpleCache.isSetParamsNX(sp1);
boolean t12 = Long.valueOf(1).equals(mockOfJedisForSimpleCache.getExpireTimePX(sp1));
boolean t11 = isSetParamsNX(sp1);
boolean t12 = Long.valueOf(1).equals(extractSetParamsExpireTimePX(sp1));
SetParams sp2 = new SetParams();
sp2.nx();
boolean t21 = mockOfJedisForSimpleCache.isSetParamsNX(sp2);
boolean t22 = Long.valueOf(1).equals(mockOfJedisForSimpleCache.getExpireTimePX(sp2));
boolean t21 = isSetParamsNX(sp2);
boolean t22 = Long.valueOf(1).equals(extractSetParamsExpireTimePX(sp2));
SetParams sp3 = new SetParams();
sp3.px(1L);
boolean t31 = mockOfJedisForSimpleCache.isSetParamsNX(sp3);
boolean t32 = Long.valueOf(1).equals(mockOfJedisForSimpleCache.getExpireTimePX(sp3));
boolean t31 = isSetParamsNX(sp3);
boolean t32 = Long.valueOf(1).equals(extractSetParamsExpireTimePX(sp3));
SetParams sp4 = new SetParams();
sp4.nx().px(1L);
boolean t41 = mockOfJedisForSimpleCache.isSetParamsNX(sp4);
boolean t42 = Long.valueOf(1).equals(mockOfJedisForSimpleCache.getExpireTimePX(sp4));
boolean t41 = isSetParamsNX(sp4);
boolean t42 = Long.valueOf(1).equals(extractSetParamsExpireTimePX(sp4));

boolean finalResult = !t11 && !t12 && t21 && !t22 && !t31 && t32 && t41 && t42;
assertTrue(finalResult);
Original file line number Diff line number Diff line change
@@ -15,17 +15,12 @@
import redis.clients.jedis.args.ListPosition;
import redis.clients.jedis.params.SetParams;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import java.util.*;

import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.when;
import static org.oba.jedis.extra.utils.test.TestingUtils.extractSetParamsExpireTimePX;
import static org.oba.jedis.extra.utils.test.TestingUtils.isSetParamsNX;

/**
* Mock of jedis methods used by the lock
@@ -188,7 +183,7 @@ synchronized String mockSet(final String key, String value, SetParams setParams)
}
if (insert) {
data.put(key, value);
Long expireTime = getExpireTimePX(setParams);
Long expireTime = extractSetParamsExpireTimePX(setParams);
if (expireTime != null){
timer.schedule(TTL.wrapTTL(() -> data.remove(key)),expireTime);
}
@@ -222,21 +217,6 @@ synchronized void put(String key, Object element) {
data.put(key, element);
}

boolean isSetParamsNX(SetParams setParams) {
boolean result = false;
for(byte[] b: setParams.getByteParams()){
String s = new String(b);
if ("nx".equalsIgnoreCase(s)){
result = true;
}
}
return result;
}

Long getExpireTimePX(SetParams setParams) {
return (Long) setParams.getParam("px");
}

synchronized ArrayList<String> dataToList(String key) {
return dataToList(key, false);
}
Original file line number Diff line number Diff line change
@@ -16,11 +16,7 @@
import java.util.Collections;
import java.util.List;

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.collections.MockOfJedisForList.CLIENT_RESPONSE_KO;
import static org.oba.jedis.extra.utils.collections.MockOfJedisForList.CLIENT_RESPONSE_OK;

@@ -44,28 +40,6 @@ public void tearDown() {
}
}

@Test
public void testParams() {
SetParams sp1 = new SetParams();
boolean t11 = mockOfJedis.isSetParamsNX(sp1);
boolean t12 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp1));
SetParams sp2 = new SetParams();
sp2.nx();
boolean t21 = mockOfJedis.isSetParamsNX(sp2);
boolean t22 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp2));
SetParams sp3 = new SetParams();
sp3.px(1L);
boolean t31 = mockOfJedis.isSetParamsNX(sp3);
boolean t32 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp3));
SetParams sp4 = new SetParams();
sp4.nx().px(1L);
boolean t41 = mockOfJedis.isSetParamsNX(sp4);
boolean t42 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp4));

boolean finalResult = !t11 && !t12 && t21 && !t22 && !t31 && t32 && t41 && t42;
assertTrue(finalResult);
}

@Test
public void testDataInsertion() throws InterruptedException {
mockOfJedis.getJedis().set("a", "A1", new SetParams());
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.oba.jedis.extra.utils.test.TestingUtils.extractSetParamsExpireTimePX;
import static org.oba.jedis.extra.utils.test.TestingUtils.isSetParamsNX;

/**
* Mock of jedis methods used by the lock
@@ -82,7 +84,7 @@ private synchronized String mockSet(final String key, String value, SetParams se
}
if (insert) {
data.put(key, value);
Long expireTime = getExpireTimePX(setParams);
Long expireTime = extractSetParamsExpireTimePX(setParams);
if (expireTime != null){
timer.schedule(TTL.wrapTTL(() -> data.remove(key)),expireTime);
}
@@ -130,23 +132,4 @@ public synchronized Map<String,String> getCurrentData() {
return new HashMap<>(data);
}

boolean isSetParamsNX(SetParams setParams) {
boolean result = false;
for(byte[] b: setParams.getByteParams()){
String s = new String(b);
if ("nx".equalsIgnoreCase(s)){
result = true;
}
}
return result;
}

Long getExpireTimePX(SetParams setParams) {
return setParams.getParam("px");
}





}
Original file line number Diff line number Diff line change
@@ -5,9 +5,7 @@
import org.junit.Test;
import redis.clients.jedis.params.SetParams;

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

public class MockOfJedisTest {

@@ -28,28 +26,6 @@ public void tearDown() {
}
}

@Test
public void testParams() {
SetParams sp1 = new SetParams();
boolean t11 = mockOfJedis.isSetParamsNX(sp1);
boolean t12 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp1));
SetParams sp2 = new SetParams();
sp2.nx();
boolean t21 = mockOfJedis.isSetParamsNX(sp2);
boolean t22 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp2));
SetParams sp3 = new SetParams();
sp3.px(1L);
boolean t31 = mockOfJedis.isSetParamsNX(sp3);
boolean t32 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp3));
SetParams sp4 = new SetParams();
sp4.nx().px(1L);
boolean t41 = mockOfJedis.isSetParamsNX(sp4);
boolean t42 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp4));

boolean finalResult = !t11 && !t12 && t21 && !t22 && !t31 && t32 && t41 && t42;
assertTrue(finalResult);
}

@Test
public void testDataInsertion() throws InterruptedException {
mockOfJedis.getJedis().set("a", "A1", new SetParams());
Original file line number Diff line number Diff line change
@@ -8,23 +8,16 @@
import org.powermock.api.support.membermodification.MemberMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.Response;
import redis.clients.jedis.Transaction;
import redis.clients.jedis.TransactionBase;
import redis.clients.jedis.*;
import redis.clients.jedis.params.SetParams;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.*;
import java.util.stream.Collectors;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.oba.jedis.extra.utils.test.TestingUtils.extractSetParamsExpireTimePX;
import static org.oba.jedis.extra.utils.test.TestingUtils.isSetParamsNX;

/**
* Mock of jedis methods used by the lock
@@ -150,7 +143,7 @@ private synchronized String mockSet(final String key, String value, SetParams se
}
if (insert) {
data.put(key, value);
Long expireTime = getExpireTimePX(setParams);
Long expireTime = extractSetParamsExpireTimePX(setParams);
if (expireTime != null){
timer.schedule(TTL.wrapTTL(() -> data.remove(key)),expireTime);
}
@@ -199,23 +192,4 @@ public synchronized Map<String,String> getCurrentData() {
return new HashMap<>(data);
}

boolean isSetParamsNX(SetParams setParams) {
boolean result = false;
for(byte[] b: setParams.getByteParams()){
String s = new String(b);
if ("nx".equalsIgnoreCase(s)){
result = true;
break;
}
}
return result;
}

Long getExpireTimePX(SetParams setParams) {
return setParams.getParam("px");
}




}
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@

import static org.junit.Assert.*;
import static org.oba.jedis.extra.utils.interruptinglocks.MockOfJedis.unitTestEnabled;
import static org.oba.jedis.extra.utils.test.TestingUtils.extractSetParamsExpireTimePX;
import static org.oba.jedis.extra.utils.test.TestingUtils.isSetParamsNX;

@RunWith(PowerMockRunner.class)
@PrepareForTest({Transaction.class, TransactionBase.class })
@@ -40,20 +42,20 @@ public void tearDown() {
@Test
public void testParams() {
SetParams sp1 = new SetParams();
boolean t11 = mockOfJedis.isSetParamsNX(sp1);
boolean t12 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp1));
boolean t11 = isSetParamsNX(sp1);
boolean t12 = Long.valueOf(1).equals(extractSetParamsExpireTimePX(sp1));
SetParams sp2 = new SetParams();
sp2.nx();
boolean t21 = mockOfJedis.isSetParamsNX(sp2);
boolean t22 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp2));
boolean t21 = isSetParamsNX(sp2);
boolean t22 = Long.valueOf(1).equals(extractSetParamsExpireTimePX(sp2));
SetParams sp3 = new SetParams();
sp3.px(1L);
boolean t31 = mockOfJedis.isSetParamsNX(sp3);
boolean t32 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp3));
boolean t31 = isSetParamsNX(sp3);
boolean t32 = Long.valueOf(1).equals(extractSetParamsExpireTimePX(sp3));
SetParams sp4 = new SetParams();
sp4.nx().px(1L);
boolean t41 = mockOfJedis.isSetParamsNX(sp4);
boolean t42 = Long.valueOf(1).equals(mockOfJedis.getExpireTimePX(sp4));
boolean t41 = isSetParamsNX(sp4);
boolean t42 = Long.valueOf(1).equals(extractSetParamsExpireTimePX(sp4));

boolean finalResult = !t11 && !t12 && t21 && !t22 && !t31 && t32 && t41 && t42;
assertTrue(finalResult);
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ private void accesLockOfCriticalZone(int sleepTime) {
} catch (InterruptedException e) {
// NOOP
}
jedis.quit();
jedis.close();
} catch (Exception e) {
LOGGER.error("Other error", e);
otherError.set(true);
Loading

0 comments on commit e381bb7

Please sign in to comment.