use of org.apache.mesos.state.Variable in project jesos by groupon.
the class JLevelDBState method store.
@Override
public Future<Variable> store(final Variable variable) {
checkNotNull(variable, "variable is null");
checkState(!closed.get(), "already closed");
checkState(variable instanceof JVariable, "can not process native variable, use JVariable");
final JVariable v = (JVariable) variable;
return executor.submit(new Callable<Variable>() {
@Override
public Variable call() throws Exception {
final WriteOptions writeOptions = new WriteOptions();
writeOptions.sync(true);
final String internedName = v.getName().intern();
synchronized (internedName) {
final JVariable current = load(internedName);
if (current == null || current.getUuid().equals(v.getUuid())) {
final JVariable update = new JVariable(internedName, v.value());
final WriteBatch writeBatch = db.createWriteBatch();
writeBatch.delete(bytes(internedName));
writeBatch.put(bytes(internedName), update.getEntry().toByteArray());
db.write(writeBatch, writeOptions);
return update;
} else {
return null;
}
}
}
});
}
use of org.apache.mesos.state.Variable in project jesos by groupon.
the class AbstractTestState method testUpdateOk.
@Test
public void testUpdateOk() 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(storedVar.mutate(newValue)).get();
assertNotNull(storedVar);
final JVariable retrievedVar = (JVariable) state.fetch("someValue").get();
assertNotNull(retrievedVar);
assertArrayEquals(storedVar.value(), retrievedVar.value());
assertEquals(storedVar.getName(), retrievedVar.getName());
assertEquals(storedVar.getUuid(), retrievedVar.getUuid());
}
use of org.apache.mesos.state.Variable in project jesos by groupon.
the class AbstractTestState method testNames.
@Test
public void testNames() throws Exception {
final State state = getState();
final byte[] value = "The quick brown fox jumps over the lazy dog.".getBytes(StandardCharsets.UTF_8);
final ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder();
for (int i = 0; i < 10; i++) {
final String key = "name-" + UUID.randomUUID().toString();
builder.add(key);
final Variable var = state.fetch(key).get();
assertTrue(var.value().length == 0);
state.store(var.mutate(value)).get();
}
final SortedSet<String> keys = builder.build();
final Iterator<String> it = state.names().get();
final SortedSet<String> entries = ImmutableSortedSet.copyOf(it);
assertEquals(keys, entries);
}
use of org.apache.mesos.state.Variable in project jesos by groupon.
the class AbstractTestState method testNonExistentValue.
@Test
public void testNonExistentValue() throws Exception {
final State state = getState();
final Variable empty = state.fetch("does-not-exist").get();
assertNotNull(empty);
assertTrue(empty.value().length == 0);
}
use of org.apache.mesos.state.Variable in project jesos by groupon.
the class AbstractTestState method testOldExpungeRefused.
@Test
public void testOldExpungeRefused() 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(var).get();
assertFalse(expunged);
final JVariable retrievedVar = (JVariable) state.fetch("someValue").get();
assertNotNull(retrievedVar);
assertArrayEquals(storedVar.value(), retrievedVar.value());
assertEquals(storedVar.getName(), retrievedVar.getName());
assertEquals(storedVar.getUuid(), retrievedVar.getUuid());
}
Aggregations