use of org.apache.mesos.state.Variable in project cassandra-mesos-deprecated by mesosphere.
the class PersistedCassandraFrameworkConfigurationTest method createInitializedState.
@NotNull
private State createInitializedState(@NotNull final String varName, @NotNull final String resourceName) throws IOException {
final State state = new InMemoryState();
final Variable var = await(state.fetch(varName));
final Variable mut = var.mutate(readConfigurationFile(resourceName));
await(state.store(mut));
return state;
}
use of org.apache.mesos.state.Variable in project jesos by groupon.
the class AbstractTestState method testExpungeOk.
@Test
public void testExpungeOk() throws Exception {
final State state = getState();
final byte[] value = "The quick brown fox jumps over the lazy dog.".getBytes(StandardCharsets.UTF_8);
final Variable var = state.fetch("someValue").get();
assertTrue(var.value().length == 0);
final JVariable storedVar = (JVariable) state.store(var.mutate(value)).get();
final boolean expunged = state.expunge(storedVar).get();
assertTrue(expunged);
final JVariable retrievedVar = (JVariable) state.fetch("someValue").get();
assertNotNull(retrievedVar);
assertEquals(0, retrievedVar.value().length);
}
use of org.apache.mesos.state.Variable in project jesos by groupon.
the class AbstractTestState method testOldUpdateRefused.
@Test
public void testOldUpdateRefused() throws Exception {
final State state = getState();
final byte[] value = "The quick brown fox jumps over the lazy dog.".getBytes(StandardCharsets.UTF_8);
final byte[] newValue = "Ich esse Autos zum Abendbrot und mache Kopfsprung ins Sandbecken. Gruen. Rot. Pferderennen.".getBytes(StandardCharsets.UTF_8);
final Variable var = state.fetch("someValue").get();
assertTrue(var.value().length == 0);
JVariable storedVar = (JVariable) state.store(var.mutate(value)).get();
storedVar = (JVariable) state.store(var.mutate(newValue)).get();
assertNull(storedVar);
}
use of org.apache.mesos.state.Variable in project jesos by groupon.
the class AbstractTestState method testTenMonkeysPressTenKeys.
@Test
public void testTenMonkeysPressTenKeys() throws Exception {
final State state = getState();
final byte[] value = "The quick brown fox jumps over the lazy dog.".getBytes(StandardCharsets.UTF_8);
final byte[] newValue = "Ich esse Autos zum Abendbrot und mache Kopfsprung ins Sandbecken. Gruen. Rot. Pferderennen.".getBytes(StandardCharsets.UTF_8);
final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
final ImmutableList.Builder<ListenableFuture<String>> builder = ImmutableList.builder();
for (int i = 0; i < 10; i++) {
builder.add(executor.submit(new Callable<String>() {
@Override
public String call() throws Exception {
final String key = "key-" + UUID.randomUUID().toString();
final Variable var = state.fetch(key).get();
assertTrue(var.value().length == 0);
JVariable storedVar = (JVariable) state.store(var.mutate(value)).get();
storedVar = (JVariable) state.store(storedVar.mutate(newValue)).get();
assertNotNull(storedVar);
final JVariable retrievedVar = (JVariable) state.fetch(key).get();
assertNotNull(retrievedVar);
assertArrayEquals(storedVar.value(), retrievedVar.value());
assertEquals(storedVar.getName(), retrievedVar.getName());
assertEquals(storedVar.getUuid(), retrievedVar.getUuid());
return key;
}
}));
}
final List<String> keys = Futures.allAsList(builder.build()).get();
for (final String key : keys) {
final JVariable retrievedVar = (JVariable) state.fetch(key).get();
assertNotNull(retrievedVar);
assertArrayEquals(newValue, retrievedVar.value());
}
executor.shutdown();
executor.awaitTermination(1, TimeUnit.DAYS);
}
use of org.apache.mesos.state.Variable in project jesos by groupon.
the class AbstractTestState method testTenMonkeysHammerOnTenKeys.
@Test
public void testTenMonkeysHammerOnTenKeys() throws Exception {
final State state = getState();
final byte[] value = "The quick brown fox jumps over the lazy dog.".getBytes(StandardCharsets.UTF_8);
final byte[] newValue = "Ich esse Autos zum Abendbrot und mache Kopfsprung ins Sandbecken. Gruen. Rot. Pferderennen.".getBytes(StandardCharsets.UTF_8);
final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
final ImmutableList.Builder<Variable> varBuilder = ImmutableList.builder();
for (int i = 0; i < 10; i++) {
final String key = "key-" + UUID.randomUUID().toString();
final Variable var = state.fetch(key).get();
assertTrue(var.value().length == 0);
final Variable storedVar = state.store(var.mutate(value)).get();
assertNotNull(storedVar);
builder.add(key);
varBuilder.add(storedVar);
}
final Set<String> keys = builder.build();
final List<Variable> variables = varBuilder.build();
final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
final ImmutableList.Builder<ListenableFuture<Integer>> resultBuilder = ImmutableList.builder();
for (int i = 0; i < 10; i++) {
resultBuilder.add(executor.submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
final ArrayList<Variable> vars = new ArrayList<>(variables);
Collections.shuffle(vars);
int updateCount = 0;
for (final Variable var : vars) {
final Variable storedVar = state.store(var.mutate(newValue)).get();
if (storedVar != null) {
updateCount++;
Thread.sleep(2L);
}
}
return updateCount;
}
}));
}
final List<Integer> results = Futures.allAsList(resultBuilder.build()).get();
int finalTally = 0;
for (final Integer result : results) {
finalTally += result;
}
assertEquals(10, finalTally);
for (final String key : keys) {
final Variable retrievedVar = state.fetch(key).get();
assertNotNull(retrievedVar);
assertArrayEquals(newValue, retrievedVar.value());
}
executor.shutdown();
executor.awaitTermination(1, TimeUnit.DAYS);
}
Aggregations