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