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");
}
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);
}
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);
}
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);
}
}
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();
}
Aggregations