Merge branch 'mrniko/master' into live-object
# Conflicts: # src/main/java/org/redisson/Redisson.javapull/527/head
commit
aa754a9799
@ -1,25 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.redisson;
|
||||
|
||||
import org.redisson.client.RedisConnection;
|
||||
import org.redisson.client.codec.Codec;
|
||||
|
||||
public interface SyncOperation<R> {
|
||||
|
||||
R execute(Codec codec, RedisConnection conn);
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.redisson.misc;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.base64.Base64;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import net.openhft.hashing.LongHashFunction;
|
||||
|
||||
public class Hash {
|
||||
|
||||
private Hash() {
|
||||
}
|
||||
|
||||
public static String hashToBase64(byte[] objectState) {
|
||||
long h1 = LongHashFunction.farmUo().hashBytes(objectState);
|
||||
long h2 = LongHashFunction.xx_r39().hashBytes(objectState);
|
||||
|
||||
ByteBuf buf = Unpooled.buffer((2 * Long.SIZE) / Byte.SIZE).writeLong(h1).writeLong(h2);
|
||||
|
||||
ByteBuf b = Base64.encode(buf);
|
||||
String s = b.toString(CharsetUtil.UTF_8);
|
||||
b.release();
|
||||
buf.release();
|
||||
return s.substring(0, s.length() - 2);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package org.redisson;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.redisson.core.RBucket;
|
||||
import org.redisson.core.RLock;
|
||||
import org.redisson.core.RSemaphore;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@RunWith(Parameterized.class)
|
||||
public class RedissonLockHeavyTest extends BaseTest {
|
||||
@Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
|
||||
return Arrays.asList(new Object[][] { { 2, 5000 }, { 2, 50000 }, { 5, 50000 }, { 10, 50000 }, { 20, 50000 }, });
|
||||
}
|
||||
|
||||
private ExecutorService executor;
|
||||
private int threads;
|
||||
private int loops;
|
||||
|
||||
public RedissonLockHeavyTest(int threads, int loops) {
|
||||
this.threads = threads;
|
||||
executor = Executors.newFixedThreadPool(threads);
|
||||
this.loops = loops;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lockUnlockRLock() throws Exception {
|
||||
for (int i = 0; i < threads; i++) {
|
||||
|
||||
Runnable worker = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int j = 0; j < loops; j++) {
|
||||
RLock lock = redisson.getLock("RLOCK_" + j);
|
||||
lock.lock();
|
||||
try {
|
||||
RBucket<String> bucket = redisson.getBucket("RBUCKET_" + j);
|
||||
bucket.set("TEST", 30, TimeUnit.SECONDS);
|
||||
RSemaphore semaphore = redisson.getSemaphore("SEMAPHORE_" + j);
|
||||
semaphore.release();
|
||||
try {
|
||||
semaphore.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
semaphore.expire(30, TimeUnit.SECONDS);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
executor.execute(worker);
|
||||
}
|
||||
executor.shutdown();
|
||||
executor.awaitTermination(threads * loops, TimeUnit.SECONDS);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue