Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
otrack committed Apr 3, 2019
1 parent e503845 commit 65cda54
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 16 deletions.
10 changes: 8 additions & 2 deletions client/src/main/java/org/infinispan/creson/AtomicBoolean.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package org.infinispan.creson;

import javax.persistence.Entity;
import javax.persistence.Id;
import java.io.Serializable;

/**
* @author Daniel
*/
@Entity
public class AtomicBoolean implements Serializable{

@Id public String name;
private boolean value;

/**
* Creates a new {@code AtomicBoolean} with the given initial value.
*
* @param initialValue the initial value
*/
public AtomicBoolean(boolean initialValue){
value = initialValue;
public AtomicBoolean(String name, boolean initialValue){
this.name = name;
this.value = initialValue;
}

/**
Expand Down
22 changes: 22 additions & 0 deletions client/src/main/java/org/infinispan/creson/AtomicReference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.infinispan.creson;

public class AtomicReference<T> {

public String name;
private T value;

public AtomicReference(){}

public AtomicReference(String name, T v){
this.name = name;
this.value = v;
}

public T get(){
return value;
}

public void set(T v){
this.value = v;
}
}
2 changes: 0 additions & 2 deletions client/src/main/java/org/infinispan/creson/CyclicBarrier.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public class CyclicBarrier {
private AtomicCounter generation;
private int parties;

public CyclicBarrier(){}

public CyclicBarrier(String name, int parties){
this.counter = new AtomicCounter(name+"-counter",0);
this.generation = new AtomicCounter(name+"generation",0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.infinispan.creson;

public class ScalableCyclicBarrier {

private static final int SLEEP = 10;

private final AtomicBoolean answers[][];
private final int parties, logParties;

private AtomicCounter identity;
private ThreadLocal<Integer> myIdentifier;

public ScalableCyclicBarrier(final String name, final int parties){
this.parties = parties;
this.logParties = (int)(Math.log(parties)/Math.log(2));
this.answers = new AtomicBoolean[parties][parties];
for(int p=0; p<parties; p++) {
for(int i=0; i<logParties; i++){
this.answers[p][i] = new AtomicBoolean(name+"-"+p+"-"+i,false);
}
}
this.identity = new AtomicCounter(name+"-identity",-1);
this.myIdentifier = new ThreadLocal<>();
}

public int await(){
if (this.myIdentifier.get()==null) this.myIdentifier.set(identity.increment());
int myId = this.myIdentifier.get();

int intended[] = new int[logParties];
int power = 1;
for(int i=0; i<logParties; i++){
intended[i] = (power + myId) % parties;
power = power * 2;
}

try{
for(int instance=0; instance<logParties; instance++) {
while (answers[intended[instance]][instance].get()) {Thread.currentThread().sleep(SLEEP);}
answers[intended[instance]][instance].set(true);
while (!answers[myId][instance].get()) {Thread.currentThread().sleep(SLEEP);}
answers[myId][instance].set(false);
}
} catch (InterruptedException e) {
// ignore
}

return 0;
}

}
3 changes: 3 additions & 0 deletions client/src/test/bin/k8s/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ else
elif [[ "$1" == "-barrier" ]]
then
template=${TMPLDIR}/barrier-test.yaml.tmpl
elif [[ "$1" == "-sbarrier" ]]
then
template=${TMPLDIR}/sbarrier-test.yaml.tmpl
else
usage
fi
Expand Down
11 changes: 8 additions & 3 deletions client/src/test/bin/local/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ IMAGE="${MAINTAINER}/${NAME}:${TAG}"
IMAGE_ID=$(docker images | grep ${NAME} | head -n 1 | awk '{print $3}')

INSTANCES="1"
CLIENTS="200"
CALLS="200"
CLIENTS="128"
CALLS="10"

CLIENT="infinispan-creson-client"
VERSION=$(cat ${PROJDIR}/pom.xml | grep version | head -n 1 | tr -d '[:blank:]' | sed s,\</*version\>,,g)

if [ $# -ne 1 ]; then
echo "usage: -[create|blobs|counters|countdownlatch|barrier|delete]"
echo "usage: -[create|blobs|counters|countdownlatch|barrier|sbarrier|delete]"
exit -1
fi

Expand Down Expand Up @@ -64,6 +64,11 @@ else
echo ">>>>> Barrier"
CLASS="org.infinispan.creson.CyclicBarrier"
INSTANCES=1
elif [[ "$1" == "-sbarrier" ]]
then
echo ">>>>> Scalable Barrier"
CLASS="org.infinispan.creson.ScalableCyclicBarrier"
INSTANCES=1
elif [[ "$1" == "-countdownlatch" ]]
then
echo ">>>>> CountDownLatch"
Expand Down
14 changes: 7 additions & 7 deletions client/src/test/java/org/infinispan/creson/Benchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class Benchmark {
@Option(name = "-parameters", usage = "parameters of the call ")
String[] parameters;

@Option(name = "-instances", required = true, usage = "#instances")
int instances;
@Option(name = "-instances", usage = "#instances")
int instances = 1;

@Option(name = "-clients", required = true, usage = "#clients")
int clients;
@Option(name = "-clients", usage = "#clients")
int clients = 1;

@Option(name = "-calls", required = true, usage = "#calls per Dockerfile")
int calls;
@Option(name = "-calls", usage = "#calls per Dockerfile")
int calls = 1;

@Option(name = "-server", usage = "connection string to server")
String server = "127.0.0.1:11222";
Expand All @@ -50,7 +50,7 @@ public void doMain(String[] args) throws ClassNotFoundException, NoSuchMethodExc
CmdLineParser parser = new CmdLineParser(this);
parser.setUsageWidth(80);
try {
if (args.length < 6)
if (args.length < 1)
throw new CmdLineException(parser, "Not enough arguments are given.");
parser.parseArgument(args);
} catch (CmdLineException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void baseAnnotation() throws Exception{
assert l1.size() == 1;
}

@Test(groups = {"creson", "stress"})
@Test(groups = {"creson", "stress"}, enabled = false)
public void baseElasticity() throws Exception {

advancedComposition();
Expand All @@ -334,7 +334,7 @@ public void baseElasticity() throws Exception {
advancedComposition();
}

@Test(groups = {"creson", "stress"})
@Test(groups = {"creson", "stress"}, enabled = false)
public void advancedElasticity() throws Exception {

ExecutorService service = Executors.newCachedThreadPool();
Expand Down

0 comments on commit 65cda54

Please sign in to comment.