Search in sources :

Example 6 with StringSerializer

use of voldemort.serialization.StringSerializer in project voldemort by voldemort.

the class AbstractStorageEngineTest method testKeyIterationWithSerialization.

@Test
public void testKeyIterationWithSerialization() {
    StorageEngine<ByteArray, byte[], byte[]> store = getStorageEngine();
    StorageEngine<String, String, String> stringStore = new SerializingStorageEngine<String, String, String>(store, new StringSerializer(), new StringSerializer(), new StringSerializer());
    Map<String, String> vals = ImmutableMap.of("a", "a", "b", "b", "c", "c", "d", "d", "e", "e");
    for (Map.Entry<String, String> entry : vals.entrySet()) stringStore.put(entry.getKey(), new Versioned<String>(entry.getValue()), null);
    ClosableIterator<String> iter = stringStore.keys();
    int count = 0;
    while (iter.hasNext()) {
        String key = iter.next();
        assertTrue(vals.containsKey(key));
        count++;
    }
    assertEquals(count, vals.size());
    iter.close();
}
Also used : SerializingStorageEngine(voldemort.store.serialized.SerializingStorageEngine) Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray) StringSerializer(voldemort.serialization.StringSerializer) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 7 with StringSerializer

use of voldemort.serialization.StringSerializer in project voldemort by voldemort.

the class AbstractStorageEngineTest method testIterationWithSerialization.

@Test
public void testIterationWithSerialization() {
    StorageEngine<ByteArray, byte[], byte[]> store = getStorageEngine();
    StorageEngine<String, String, String> stringStore = SerializingStorageEngine.wrap(store, new StringSerializer(), new StringSerializer(), new StringSerializer());
    Map<String, String> vals = ImmutableMap.of("a", "a", "b", "b", "c", "c", "d", "d", "e", "e");
    for (Map.Entry<String, String> entry : vals.entrySet()) stringStore.put(entry.getKey(), new Versioned<String>(entry.getValue()), null);
    ClosableIterator<Pair<String, Versioned<String>>> iter = stringStore.entries();
    int count = 0;
    while (iter.hasNext()) {
        Pair<String, Versioned<String>> keyAndVal = iter.next();
        assertTrue(vals.containsKey(keyAndVal.getFirst()));
        assertEquals(vals.get(keyAndVal.getFirst()), keyAndVal.getSecond().getValue());
        count++;
    }
    assertEquals(count, vals.size());
    iter.close();
}
Also used : Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray) StringSerializer(voldemort.serialization.StringSerializer) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Pair(voldemort.utils.Pair) Test(org.junit.Test)

Example 8 with StringSerializer

use of voldemort.serialization.StringSerializer in project voldemort by voldemort.

the class AdminServiceBasicTest method bootstrapMetadata.

/**
 * Function to return the String representation of a Metadata key
 * (stores.xml or an individual store)
 *
 * @param key specifies the metadata key to retrieve
 * @return String representation of the value associated with the metadata
 *         key
 */
private String bootstrapMetadata(String metadataKey) {
    Node serverNode = servers[0].getIdentityNode();
    Store<ByteArray, byte[], byte[]> remoteStore = socketStoreFactory.create(MetadataStore.METADATA_STORE_NAME, serverNode.getHost(), serverNode.getSocketPort(), RequestFormatType.VOLDEMORT_V2, RequestRoutingType.NORMAL);
    Store<String, String, byte[]> store = SerializingStore.wrap(remoteStore, new StringSerializer("UTF-8"), new StringSerializer("UTF-8"), new IdentitySerializer());
    List<Versioned<String>> found = store.get(metadataKey, null);
    assertEquals(found.size(), 1);
    String valueStr = found.get(0).getValue();
    return valueStr;
}
Also used : Versioned(voldemort.versioning.Versioned) Node(voldemort.cluster.Node) ByteArray(voldemort.utils.ByteArray) IdentitySerializer(voldemort.serialization.IdentitySerializer) StringSerializer(voldemort.serialization.StringSerializer)

Example 9 with StringSerializer

use of voldemort.serialization.StringSerializer in project voldemort by voldemort.

the class CachingStoreClientFactoryTest method testCaching.

@Test
public void testCaching() {
    StoreClientFactory inner = new MockStoreClientFactory(new StringSerializer(), new StringSerializer(), null);
    StoreClientFactory spyFactory = spy(inner);
    StoreClientFactory cachingFactory = new CachingStoreClientFactory(spyFactory);
    TimeBasedInconsistencyResolver<Object> resolver = new TimeBasedInconsistencyResolver<Object>();
    when(spyFactory.<Object, Object>getStoreClient(anyString())).thenCallRealMethod();
    when(spyFactory.<Object, Object>getStoreClient(anyString(), eq(resolver))).thenCallRealMethod();
    for (int i = 0; i < 10; i++) {
        assertNotNull(cachingFactory.getStoreClient("foo"));
        assertNotNull(cachingFactory.getStoreClient("foo", resolver));
    }
    verify(spyFactory, times(1)).getStoreClient("foo", resolver);
    verify(spyFactory, times(1)).getStoreClient("foo", null);
}
Also used : TimeBasedInconsistencyResolver(voldemort.versioning.TimeBasedInconsistencyResolver) StringSerializer(voldemort.serialization.StringSerializer) Test(org.junit.Test)

Example 10 with StringSerializer

use of voldemort.serialization.StringSerializer in project voldemort by voldemort.

the class StringSorter method main.

public static void main(String[] args) throws Exception {
    if (args.length != 3)
        Utils.croak("USAGE: java StringSorter inputfile internal_sort_size num_threads");
    String input = args[0];
    int internalSortSize = Integer.parseInt(args[1]);
    int numThreads = Integer.parseInt(args[2]);
    ExternalSorter<String> sorter = new ExternalSorter<String>(new StringSerializer(), internalSortSize, numThreads);
    @SuppressWarnings("unchecked") Iterator<String> it = new LineIterator(new BufferedReader(new FileReader(input), 10 * 1024 * 1024));
    String separator = Utils.NEWLINE;
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out), 10 * 1024 * 1024);
    for (String line : sorter.sorted(it)) {
        writer.write(line);
        writer.write(separator);
    }
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) OutputStreamWriter(java.io.OutputStreamWriter) StringSerializer(voldemort.serialization.StringSerializer) LineIterator(org.apache.commons.io.LineIterator) BufferedWriter(java.io.BufferedWriter)

Aggregations

StringSerializer (voldemort.serialization.StringSerializer)13 ByteArray (voldemort.utils.ByteArray)9 Versioned (voldemort.versioning.Versioned)5 File (java.io.File)4 Test (org.junit.Test)4 IdentitySerializer (voldemort.serialization.IdentitySerializer)4 Node (voldemort.cluster.Node)3 VoldemortConfig (voldemort.server.VoldemortConfig)3 Pair (voldemort.utils.Pair)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Serializer (voldemort.serialization.Serializer)2 StorageConfiguration (voldemort.store.StorageConfiguration)2 StoreDefinition (voldemort.store.StoreDefinition)2 BdbStorageConfiguration (voldemort.store.bdb.BdbStorageConfiguration)2 SerializingStore (voldemort.store.serialized.SerializingStore)2 Props (voldemort.utils.Props)2 Database (com.sleepycat.je.Database)1 DatabaseConfig (com.sleepycat.je.DatabaseConfig)1