use of voldemort.client.ClientConfig in project javaee7-samples by javaee-samples.
the class PersonSessionBean method initDB.
@PostConstruct
private void initDB() {
// // start embedded
// VoldemortConfig config = VoldemortConfig.loadFromEnvironmentVariable();
// VoldemortServer server = new VoldemortServer(config);
// server.start();
// bootstrap
String bootstrapUrl = "tcp://localhost:6666";
StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
// create a client that executes operations on a single store
client = factory.getStoreClient("test");
}
use of voldemort.client.ClientConfig in project voldemort by voldemort.
the class TestClientShutdown method main.
public static void main(String[] args) throws Exception {
if (args.length < 2 || args.length > 3)
Utils.croak("USAGE: java VoldemortClientShell store_name bootstrap_url [command_file]");
String storeName = args[0];
String bootstrapUrl = args[1];
StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setEnableLazy(false).setBootstrapUrls(bootstrapUrl));
DefaultStoreClient<Object, Object> client = null;
try {
client = (DefaultStoreClient<Object, Object>) factory.getStoreClient(storeName);
} catch (Exception e) {
Utils.croak("Could not connect to server: " + e.getMessage());
}
System.out.println("Established connection to " + storeName + " via " + bootstrapUrl);
client.get("hello");
System.out.println("Got value");
}
use of voldemort.client.ClientConfig in project voldemort by voldemort.
the class RemoteDataGenerator method generateData.
/**
* Populate the store with
*
* @param requests key-value pairs with key of size, appending
* @param postfix for uniqueness.
*
* @param keySize bytes and value of size
* @param valueSize bytes
* @param requests How many key-value pairs to generate
* @param keySize Size (in bytes) of the key
* @param valueSize Size (in bytes) of the value
* @param postfix Postfix to append (for uniqueness)
*/
public void generateData(int requests, int keySize, int valueSize, String postfix) {
StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(url).setMaxThreads(workers));
StoreClient<String, String> client = storeClientFactory.getStoreClient(storeName);
for (int i = 0; i < requests; i++) {
StringBuilder keyBuilder = new StringBuilder(makeString(keySize)).append(i);
StringBuilder valueBuilder = new StringBuilder(makeString(valueSize)).append(i);
if (postfix != null) {
keyBuilder.append(postfix);
}
try {
client.put(keyBuilder.toString(), valueBuilder.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of voldemort.client.ClientConfig in project voldemort by voldemort.
the class HintedHandoffTestEnvironment method run.
@Override
public void run() {
Random random = new Random(System.currentTimeMillis());
cluster = VoldemortTestConstants.getEightNodeClusterWithZones();
storeDef = storeDefBuilder.build();
// setup store engines
for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
// do only once
createInnerStore(nodeId);
}
for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
try {
startServer(nodeId);
} catch (IOException e) {
logger.error("Server " + nodeId + "failed to start", e);
}
}
// setup client factory
String bootstrapUrl = cluster.getNodeById(0).getSocketUrl().toString();
factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
// wait for start of servers
startFinishLatch.countDown();
try {
boolean wrapUpSignal = false;
while (!wrapUpSignal) {
if (logger.isInfoEnabled()) {
logger.info("Will sleep for a while or until seeing wrapUpSignal. sleep time: " + statusRefreshIntervalSecond + " Seconds");
}
wrapUpSignal = wrapUpRequestLatch.await(statusRefreshIntervalSecond, TimeUnit.SECONDS);
if (logger.isInfoEnabled()) {
if (wrapUpSignal) {
logger.info("Wake Up and wrap up. Make all servers NORMAL");
minNodesAvailable = NUM_NODES_TOTAL;
} else {
logger.info("Wake Up and decide new failure statuses");
}
for (Map.Entry<Integer, Store<ByteArray, byte[], byte[]>> entry : realStores.entrySet()) {
InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]> engine = (InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]>) entry.getValue();
logger.info("Outstanding Put Assertions of node [" + entry.getKey() + "]: " + engine.getFailedAssertions().size());
}
}
// decide random number of cluster nodes(at least 1 alive) with
// random ids to fail
Integer numNodesToFail = random.nextInt(NUM_NODES_TOTAL - minNodesAvailable + 1);
Set<Integer> nodesToFail = getUniqueRandomNumbers(NUM_NODES_TOTAL, numNodesToFail);
if (logger.isInfoEnabled()) {
logger.info("Setting nodes to Fail: " + nodesToFail.toString());
}
for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
if (nodesToFail.contains(nodeId)) {
// fail a node if it's normal
if (nodesStatus.get(nodeId) == NodeStatus.NORMAL) {
// random pick one failure node
Integer failureMode = random.nextInt(3);
switch(failureMode) {
case 0:
makeNodeDown(nodeId);
break;
case 1:
makeNodeSlow(nodeId);
break;
case 2:
makeNodeBdbError(nodeId);
break;
}
}
// otherwise, leave unchanged
} else {
// make node normal if not normal
if (nodesStatus.get(nodeId) != NodeStatus.NORMAL) {
makeNodeNormal(nodeId);
}
// otherwise, leave unchanged
}
}
}
} catch (InterruptedException e) {
} finally {
wrapUpFinishLatch.countDown();
}
}
use of voldemort.client.ClientConfig in project voldemort by voldemort.
the class CompressingStoreTest method testPutGetWithSocketService.
@Test
public void testPutGetWithSocketService() throws Exception {
int freePort = ServerTestUtils.findFreePort();
String clusterXml = VoldemortTestConstants.getOneNodeClusterXml();
clusterXml = clusterXml.replace("<socket-port>6666</socket-port>", "<socket-port>" + freePort + "</socket-port>");
AbstractSocketService socketService = ServerTestUtils.getSocketService(useNio, clusterXml, VoldemortTestConstants.getCompressedStoreDefinitionsXml(), "test", freePort);
socketService.start();
Thread.sleep(1000);
SocketStoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls("tcp://localhost:" + freePort).setMaxBootstrapRetries(10));
StoreClient<String, String> storeClient = storeClientFactory.getStoreClient("test");
storeClient.put("someKey", "someValue");
assertEquals(storeClient.getValue("someKey"), "someValue");
socketService.stop();
}
Aggregations