Search in sources :

Example 91 with TypeToken

use of com.google.common.reflect.TypeToken in project CorfuDB by CorfuDB.

the class ObjectsViewTest method unrelatedTransactionDoesNotConflict.

@Test
@SuppressWarnings("unchecked")
public void unrelatedTransactionDoesNotConflict() throws Exception {
    //begin tests
    CorfuRuntime r = getDefaultRuntime();
    Map<String, String> smrMap = r.getObjectsView().build().setStreamName("map a").setTypeToken(new TypeToken<SMRMap<String, String>>() {
    }).open();
    Map<String, String> smrMapB = r.getObjectsView().build().setStreamName("map b").setTypeToken(new TypeToken<SMRMap<String, String>>() {
    }).open();
    smrMap.put("a", "b");
    r.getObjectsView().TXBegin();
    String b = smrMap.get("a");
    smrMapB.put("b", b);
    r.getObjectsView().TXEnd();
    //this TX should not conflict
    assertThat(smrMap).doesNotContainKey("b");
    r.getObjectsView().TXBegin();
    b = smrMap.get("a");
    smrMap.put("b", b);
    r.getObjectsView().TXEnd();
    assertThat(smrMap).containsEntry("b", "b");
}
Also used : TypeToken(com.google.common.reflect.TypeToken) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 92 with TypeToken

use of com.google.common.reflect.TypeToken in project CorfuDB by CorfuDB.

the class FGMapTest method abortRateIsLowForSimpleTX.

@Test
@SuppressWarnings("unchecked")
public void abortRateIsLowForSimpleTX() throws Exception {
    getDefaultRuntime();
    Map<String, String> testMap = getRuntime().getObjectsView().build().setStreamName("test").setTypeToken(new TypeToken<FGMap<String, String>>() {
    }).open();
    final int num_threads = PARAMETERS.CONCURRENCY_SOME;
    final int num_records = PARAMETERS.NUM_ITERATIONS_LOW;
    AtomicInteger aborts = new AtomicInteger();
    testMap.clear();
    scheduleConcurrently(num_threads, threadNumber -> {
        int base = threadNumber * num_records;
        for (int i = base; i < base + num_records; i++) {
            try {
                getRuntime().getObjectsView().TXBegin();
                assertThat(testMap.put(Integer.toString(i), Integer.toString(i))).isEqualTo(null);
                getRuntime().getObjectsView().TXEnd();
            } catch (TransactionAbortedException tae) {
                aborts.incrementAndGet();
            }
        }
    });
    long startTime = System.currentTimeMillis();
    executeScheduled(num_threads, PARAMETERS.TIMEOUT_LONG);
    calculateRequestsPerSecond("TPS", num_records * num_threads, startTime);
    calculateAbortRate(aborts.get(), num_records * num_threads);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TypeToken(com.google.common.reflect.TypeToken) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 93 with TypeToken

use of com.google.common.reflect.TypeToken in project CorfuDB by CorfuDB.

the class SMRMapTest method modificationDuringTransactionCausesAbort.

@Test
@SuppressWarnings("unchecked")
public void modificationDuringTransactionCausesAbort() throws Exception {
    Map<String, String> testMap = getRuntime().getObjectsView().build().setStreamName("A").setTypeToken(new TypeToken<SMRMap<String, String>>() {
    }).open();
    assertThat(testMap.put("a", "z"));
    getRuntime().getObjectsView().TXBegin();
    assertThat(testMap.put("a", "a")).isEqualTo("z");
    assertThat(testMap.put("a", "b")).isEqualTo("a");
    assertThat(testMap.get("a")).isEqualTo("b");
    CompletableFuture cf = CompletableFuture.runAsync(() -> {
        Map<String, String> testMap2 = getRuntime().getObjectsView().build().setStreamName("A").setSerializer(Serializers.JSON).addOption(ObjectOpenOptions.NO_CACHE).setTypeToken(new TypeToken<SMRMap<String, String>>() {
        }).open();
        getRuntime().getObjectsView().TXBegin();
        testMap2.put("a", "f");
        getRuntime().getObjectsView().TXEnd();
    });
    cf.join();
    assertThatThrownBy(() -> getRuntime().getObjectsView().TXEnd()).isInstanceOf(TransactionAbortedException.class);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TypeToken(com.google.common.reflect.TypeToken) ToString(lombok.ToString) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 94 with TypeToken

use of com.google.common.reflect.TypeToken in project CorfuDB by CorfuDB.

the class SMRMultiLogunitTest method multiThreadedManyWritesThenRead.

/**
     * Multi Threaded.
     * Verify reads after multiple non-transactional writes done concurrently (using 2 threads)
     *
     */
@Test
public void multiThreadedManyWritesThenRead() {
    int numKeys = ONE_THOUSAND;
    ObjectsView view = getRuntime().getObjectsView();
    Map<String, String> testMap = getRuntime().getObjectsView().build().setStreamName("test").setTypeToken(new TypeToken<SMRMap<String, String>>() {
    }).open();
    AtomicInteger threadsComplete = new AtomicInteger(0);
    addTestStep((step) -> {
        for (int i = 0; i < numKeys; i++) {
            String key = "key" + String.valueOf(i);
            String val = "value" + String.valueOf(step) + "_" + String.valueOf(i);
            testMap.put(key, val);
            if (i % ONE_HUNDRED == 0) {
                Thread.yield();
            }
        }
        threadsComplete.incrementAndGet();
    });
    try {
        scheduleThreaded(2, 2);
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(2, threadsComplete.get());
    for (int i = 0; i < numKeys; i++) {
        String key = "key" + String.valueOf(i);
        String val = testMap.get(key);
        assertNotNull(val);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TypeToken(com.google.common.reflect.TypeToken) ObjectsView(org.corfudb.runtime.view.ObjectsView) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 95 with TypeToken

use of com.google.common.reflect.TypeToken in project CorfuDB by CorfuDB.

the class TXConflictScenariosTest method finegrainedUpdatesDoNotConflict.

@Test
@SuppressWarnings("unchecked")
public void finegrainedUpdatesDoNotConflict() throws Exception {
    AtomicBoolean commitStatus = new AtomicBoolean(true);
    Map<String, String> testMap = getMap();
    Map<String, String> testMap2 = (Map<String, String>) instantiateCorfuObject(new TypeToken<SMRMap<String, String>>() {
    }, "test stream");
    t(1, () -> TXBegin());
    t(1, () -> testMap.put("a", "a"));
    t(1, () -> assertThat(testMap.put("a", "b")).isEqualTo("a"));
    t(2, () -> TXBegin());
    t(2, () -> testMap2.put("b", "f"));
    t(2, () -> assertThat(testMap2.put("b", "g")).isEqualTo("f"));
    t(2, () -> TXEnd());
    t(1, () -> {
        try {
            TXEnd();
        } catch (TransactionAbortedException te) {
            commitStatus.set(false);
        }
    });
    // verify that both transactions committed successfully
    assertThat(commitStatus.get()).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TypeToken(com.google.common.reflect.TypeToken) SMRMap(org.corfudb.runtime.collections.SMRMap) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException) Test(org.junit.Test)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)135 Test (org.junit.Test)60 HttpResponse (co.cask.common.http.HttpResponse)26 URL (java.net.URL)24 ServiceResponse (com.microsoft.rest.ServiceResponse)22 Response (retrofit2.Response)22 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)18 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)17 PipedInputStream (java.io.PipedInputStream)17 PipedOutputStream (java.io.PipedOutputStream)17 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)16 List (java.util.List)16 Map (java.util.Map)11 ImmutableList (com.google.common.collect.ImmutableList)9 Type (java.lang.reflect.Type)9 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)9 NotFoundException (co.cask.cdap.common.NotFoundException)8 VirtualMachineScaleSetVMInstanceIDs (com.microsoft.azure.management.compute.VirtualMachineScaleSetVMInstanceIDs)8 Gson (com.google.gson.Gson)7 JsonObject (com.google.gson.JsonObject)7