Search in sources :

Example 11 with State

use of org.apache.mesos.state.State 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);
}
Also used : Variable(org.apache.mesos.state.Variable) State(org.apache.mesos.state.State) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Test(org.junit.Test)

Example 12 with State

use of org.apache.mesos.state.State 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());
}
Also used : Variable(org.apache.mesos.state.Variable) State(org.apache.mesos.state.State) Test(org.junit.Test)

Example 13 with State

use of org.apache.mesos.state.State 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);
}
Also used : Variable(org.apache.mesos.state.Variable) State(org.apache.mesos.state.State) Test(org.junit.Test)

Example 14 with State

use of org.apache.mesos.state.State in project jesos by groupon.

the class AbstractTestState method testSetAndGet.

@Test
public void testSetAndGet() 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 Variable newVar = var.mutate(value);
    final JVariable storedVar = (JVariable) state.store(newVar).get();
    assertNotNull(storedVar);
    final JVariable retrievedVar = (JVariable) state.fetch("someValue").get();
    assertNotNull(retrievedVar);
    assertArrayEquals(newVar.value(), retrievedVar.value());
    assertArrayEquals(storedVar.value(), retrievedVar.value());
    assertEquals(storedVar.getName(), retrievedVar.getName());
    assertEquals(storedVar.getUuid(), retrievedVar.getUuid());
}
Also used : Variable(org.apache.mesos.state.Variable) State(org.apache.mesos.state.State) Test(org.junit.Test)

Example 15 with State

use of org.apache.mesos.state.State 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());
}
Also used : Variable(org.apache.mesos.state.Variable) State(org.apache.mesos.state.State) Test(org.junit.Test)

Aggregations

State (org.apache.mesos.state.State)16 Test (org.junit.Test)14 Variable (org.apache.mesos.state.Variable)11 InMemoryState (org.apache.mesos.state.InMemoryState)5 ImmutableList (com.google.common.collect.ImmutableList)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 CassandraFrameworkProtos (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos)2 Callable (java.util.concurrent.Callable)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 ExternalDc (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.ExternalDc)1 HealthReportService (io.mesosphere.mesos.frameworks.cassandra.scheduler.health.HealthReportService)1 Clock (io.mesosphere.mesos.util.Clock)1 SystemClock (io.mesosphere.mesos.util.SystemClock)1 URI (java.net.URI)1