Search in sources :

Example 1 with Variable

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;
}
Also used : Variable(org.apache.mesos.state.Variable) InMemoryState(org.apache.mesos.state.InMemoryState) State(org.apache.mesos.state.State) InMemoryState(org.apache.mesos.state.InMemoryState) NotNull(javax.validation.constraints.NotNull)

Example 2 with Variable

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

Example 3 with Variable

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

Example 4 with Variable

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);
}
Also used : Variable(org.apache.mesos.state.Variable) State(org.apache.mesos.state.State) ImmutableList(com.google.common.collect.ImmutableList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 5 with Variable

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);
}
Also used : Variable(org.apache.mesos.state.Variable) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) ImmutableSet(com.google.common.collect.ImmutableSet) State(org.apache.mesos.state.State) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Test(org.junit.Test)

Aggregations

Variable (org.apache.mesos.state.Variable)14 State (org.apache.mesos.state.State)11 Test (org.junit.Test)11 ImmutableList (com.google.common.collect.ImmutableList)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 Callable (java.util.concurrent.Callable)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NotNull (javax.validation.constraints.NotNull)1 InMemoryState (org.apache.mesos.state.InMemoryState)1 WriteBatch (org.iq80.leveldb.WriteBatch)1 WriteOptions (org.iq80.leveldb.WriteOptions)1 Iq80DBFactory.asString (org.iq80.leveldb.impl.Iq80DBFactory.asString)1