Search in sources :

Example 1 with CustomSerializer

use of org.corfudb.CustomSerializer in project CorfuDB by CorfuDB.

the class CorfuSMRObjectProxyTest method canUseCustomSerializer.

/** Disabled pending resolution of issue #285
    @Test
    public void deadLockTest() throws Exception {
        CorfuRuntime runtime = getDefaultRuntime().connect();
        Map<String, Integer> map =
                runtime.getObjectsView()
                        .build()
                        .setStreamName("M")
                        .setType(SMRMap.class)
                        .open();

        for(int x = 0; x < PARAMETERS.NUM_ITERATIONS_LOW; x++) {
            // thread 1: update "a" and "b" atomically
            Thread t1 = new Thread(() -> {
                runtime.getObjectsView().TXBegin();
                map.put("a", 1);
                map.put("b", 1);
                runtime.getObjectsView().TXEnd();
            }
            );
            t1.start();

            // thread 2: read "a", then "b"
            Thread t2 = new Thread(() -> {
                map.get("a");
                map.get("b");
            });
            t2.start();

            t1.join(PARAMETERS.TIMEOUT_NORMAL.toMillis());
            t2.join(PARAMETERS.TIMEOUT_NORMAL.toMillis());

            assertThat(t1.isAlive()).isFalse();
            assertThat(t2.isAlive()).isFalse();
        }
    }

    @Test
    @SuppressWarnings("unchecked")
    public void canUsePrimitiveSerializer()
            throws Exception {
        //begin tests
        CorfuRuntime r = getDefaultRuntime().connect();
        TestClassWithPrimitives test = r.getObjectsView().build()
                .setType(TestClassWithPrimitives.class)
                .setStreamName("test")
                .setSerializer(Serializers.PRIMITIVE)
                .open();

        test.setPrimitive("hello world".getBytes());
        assertThat(test.getPrimitive())
                .isEqualTo("hello world".getBytes());
    }
     **/
@Test
@SuppressWarnings("unchecked")
public void canUseCustomSerializer() throws Exception {
    //Register a custom serializer and use it with an SMR object
    ISerializer customSerializer = new CustomSerializer((byte) (Serializers.SYSTEM_SERIALIZERS_COUNT + 1));
    Serializers.registerSerializer(customSerializer);
    CorfuRuntime r = getDefaultRuntime();
    Map<String, String> test = r.getObjectsView().build().setType(SMRMap.class).setStreamName("test").setSerializer(customSerializer).open();
    test.put("a", "b");
    test.get("a");
    assertThat(test.get("a")).isEqualTo("b");
}
Also used : SMRMap(org.corfudb.runtime.collections.SMRMap) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) CustomSerializer(org.corfudb.CustomSerializer) ISerializer(org.corfudb.util.serializer.ISerializer) Test(org.junit.Test)

Aggregations

CustomSerializer (org.corfudb.CustomSerializer)1 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)1 SMRMap (org.corfudb.runtime.collections.SMRMap)1 ISerializer (org.corfudb.util.serializer.ISerializer)1 Test (org.junit.Test)1