org.apache.mesos.state.State Java Examples

The following examples show how to use org.apache.mesos.state.State. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractTestState.java    From jesos with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: AbstractTestState.java    From jesos with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #3
Source File: AbstractTestState.java    From jesos with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: AbstractTestState.java    From jesos with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: AbstractTestState.java    From jesos with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #6
Source File: PersistedCassandraFrameworkConfigurationTest.java    From cassandra-mesos-deprecated with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #7
Source File: SerializableZookeeperStateTest.java    From elasticsearch with Apache License 2.0 5 votes vote down vote up
@Before
public void before() throws IOException {
    state = mock(State.class);
    variable = mock(Variable.class);
    when(variable.value()).thenReturn(writeVariable(SERIALIZABLE_OBJECT));
    future = CompletableFuture.completedFuture(variable);
    serializableState = new SerializableZookeeperState(state);
    when(state.fetch(anyString())).thenReturn(future);
    when(state.store(any(Variable.class))).thenReturn(future);
}
 
Example #8
Source File: PersistedCassandraFrameworkConfigurationTest.java    From cassandra-mesos-deprecated with Apache License 2.0 5 votes vote down vote up
@Test
public void generatingNewConfigAllowsFrameworkNameAndClusterNameToBeDifferent() throws Exception {
    final State state = new InMemoryState();

    final PersistedCassandraFrameworkConfiguration configuration = new PersistedCassandraFrameworkConfiguration(
        state,
        "cassandra.frameworkName",
        15,
        15,
        "2.1.4",
        1.0,
        2048,
        2048,
        1024,
        1,
        1,
        "*",
        "./backup",
        ".",
        true,
        true,
        "rack1",
        "dc1",
        Collections.<ExternalDc>emptyList(),
        "clusterName"
    );

    assertThat(configuration.frameworkName()).isEqualTo("cassandra.frameworkName");
    assertThat(configuration.clusterName()).isEqualTo("clusterName");
}
 
Example #9
Source File: PersistedCassandraFrameworkConfigurationTest.java    From cassandra-mesos-deprecated with Apache License 2.0 5 votes vote down vote up
@Test
public void separationOfFrameworkNameAndClusterNamePreservesOriginalClusterName() throws Exception {
    final State state = createInitializedState("CassandraFrameworkConfiguration", "/CassandraFrameworkConfiguration_v0.2.0.bin");

    final PersistedCassandraFrameworkConfiguration configuration = new PersistedCassandraFrameworkConfiguration(
        state,
        "frameworkName should be cassandra.cluster not this value",
        15,
        15,
        "2.1.4",
        1.0,
        2048,
        2048,
        1024,
        1,
        1,
        "*",
        "./backup",
        ".",
        true,
        true,
        "rack1",
        "dc1",
        Collections.<ExternalDc>emptyList(),
        "clusterName should be cassandra.cluster not this value"
    );

    assertThat(configuration.frameworkName()).isEqualTo("cassandra.cluster");
    assertThat(configuration.clusterName()).isEqualTo("cassandra.cluster");
}
 
Example #10
Source File: PersistedCassandraClusterHealthCheckHistoryTest.java    From cassandra-mesos-deprecated with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllOscillatingOutOfOrder() throws Exception {
    final State state = new InMemoryState();
    final PersistedCassandraClusterHealthCheckHistory hcHistory = new PersistedCassandraClusterHealthCheckHistory(state);

    hcHistory.record("abc", 10, unhealthy());
    hcHistory.record("abc", 11,   healthy());
    hcHistory.record("abc", 13, unhealthy());
    hcHistory.record("abc", 16, unhealthy());
    hcHistory.record("abc", 14,   healthy());
    hcHistory.record("abc", 19, unhealthy());
    hcHistory.record("abc", 15,   healthy());
    hcHistory.record("abc", 12,   healthy());
    hcHistory.record("abc", 25, unhealthy());
    hcHistory.record("abc", 17,   healthy());
    hcHistory.record("abc", 20,   healthy());
    hcHistory.record("abc", 21,   healthy());
    hcHistory.record("abc", 22, unhealthy());
    hcHistory.record("abc", 24,   healthy());
    hcHistory.record("abc", 18,   healthy());
    hcHistory.record("abc", 23,   healthy());

    final CassandraFrameworkProtos.CassandraClusterHealthCheckHistory history = hcHistory.get();
    final List<CassandraFrameworkProtos.HealthCheckHistoryEntry> list = history.getEntriesList();

    CassandraFrameworkProtos.HealthCheckHistoryEntry prev = null;
    for (final CassandraFrameworkProtos.HealthCheckHistoryEntry entry : list) {
        if (prev != null) {
            assertThat(entry.getTimestampStart()).isLessThanOrEqualTo(entry.getTimestampEnd());
            assertThat(prev.getTimestampEnd()).isLessThanOrEqualTo(entry.getTimestampStart());
        }
        prev = entry;
    }
}
 
Example #11
Source File: StatePersistedObject.java    From cassandra-mesos-deprecated with Apache License 2.0 5 votes vote down vote up
public StatePersistedObject(
    @NotNull final String variableName,
    @NotNull final State state,
    @NotNull final Supplier<A> defaultValue,
    @NotNull final Function<byte[], A> deserializer,
    @NotNull final Function<A, byte[]> serializer
) {
    this.deserializer = deserializer;
    this.serializer = serializer;
    this.defaultValue = defaultValue.get();
    this.state = state;
    this.var = await(state.fetch(variableName));
}
 
Example #12
Source File: AbstractTestState.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpungeNonExistentValue()
    throws Exception
{
    final State state = getState();

    final Variable empty = state.fetch("does-not-exist").get();
    assertNotNull(empty);
    assertTrue(empty.value().length == 0);

    final boolean expunged = state.expunge(empty).get();
    assertFalse(expunged);
}
 
Example #13
Source File: AbstractTestState.java    From jesos with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: AbstractTestState.java    From jesos with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: TestJZookeeperState.java    From jesos with Apache License 2.0 4 votes vote down vote up
@Override
protected State getState()
{
    return state;
}
 
Example #16
Source File: ExecutorCounter.java    From cassandra-mesos-deprecated with Apache License 2.0 4 votes vote down vote up
public ExecutorCounter(final @NotNull State state, final long defaultValue) {
    this.state = state;
    this.defaultValue = defaultValue;

    this.var = await(state.fetch(VARIABLE_NAME));
}
 
Example #17
Source File: TestJLevelDBState.java    From jesos with Apache License 2.0 4 votes vote down vote up
@Override
protected State getState()
{
    return state;
}
 
Example #18
Source File: MesosModule.java    From incubator-myriad with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
State providesStateStore(MyriadConfiguration cfg) {
  return new ZooKeeperState(cfg.getZkServers(), cfg.getZkTimeout(), TimeUnit.MILLISECONDS, "/myriad/" + cfg.getFrameworkName());
}
 
Example #19
Source File: MyriadState.java    From incubator-myriad with Apache License 2.0 4 votes vote down vote up
public MyriadState(State stateStore) {
  this.stateStore = stateStore;
}
 
Example #20
Source File: AbstractTestState.java    From jesos with Apache License 2.0 votes vote down vote up
protected abstract State getState();