use of voldemort.xml.ClusterMapper in project voldemort by voldemort.
the class HttpStoreTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
Cluster cluster = ServerTestUtils.getLocalCluster(1);
Node node = cluster.getNodes().iterator().next();
context = ServerTestUtils.getJettyServer(new ClusterMapper().writeCluster(cluster), VoldemortTestConstants.getSimpleStoreDefinitionsXml(), "users", RequestFormatType.VOLDEMORT_V1, node.getHttpPort());
server = context.getServer();
ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(), 5000, TimeUnit.MILLISECONDS);
httpClient = new DefaultHttpClient(connectionManager);
httpStore = ServerTestUtils.getHttpStore("users", RequestFormatType.VOLDEMORT_V1, node.getHttpPort(), httpClient);
}
use of voldemort.xml.ClusterMapper in project voldemort by voldemort.
the class TestDistribution method main.
public static void main(String[] args) throws Exception {
if (args.length < 2)
Utils.croak("USAGE: java TestDistribution cluster.xml replication_factor max_id");
long start = System.currentTimeMillis();
File file = new File(args[0]);
int repFactor = Integer.parseInt(args[1]);
int maxVal = Integer.parseInt(args[2]);
ClusterMapper mapper = new ClusterMapper();
Cluster cluster = mapper.readCluster(file);
RoutingStrategy strategy = new ConsistentRoutingStrategy(cluster, repFactor);
JsonTypeSerializer serializer = new JsonTypeSerializer(JsonTypeDefinition.INT32);
Map<Integer, Integer> counts = new HashMap<Integer, Integer>();
for (int i = 0; i < maxVal; i++) {
for (Node node : strategy.routeRequest(serializer.toBytes(i))) {
int newCount = 1;
if (counts.get(node.getId()) != null) {
newCount = counts.get(node.getId()) + 1;
}
counts.put(node.getId(), newCount);
}
}
int sum = 0;
int totalCounts = 0;
for (int countVal : counts.values()) {
sum += countVal;
totalCounts++;
}
int avg = sum / totalCounts;
NumberFormat percent = NumberFormat.getPercentInstance();
percent.setMaximumFractionDigits(2);
System.out.println("Node\tKeys\tPercent\tVariation");
for (int nodeId : counts.keySet()) {
System.out.println(nodeId + "\t" + counts.get(nodeId) + "\t" + percent.format(counts.get(nodeId) / (double) sum) + "\t" + percent.format((counts.get(nodeId) - avg) / (double) counts.get(nodeId)));
}
double msPerHash = (System.currentTimeMillis() - start) / ((double) repFactor * maxVal);
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(10);
System.out.println(nf.format(msPerHash) + " ms per hash");
}
use of voldemort.xml.ClusterMapper in project voldemort by voldemort.
the class ServerTestUtils method createServerConfigWithDefs.
public static VoldemortConfig createServerConfigWithDefs(boolean useNio, int nodeId, String baseDir, Cluster cluster, List<StoreDefinition> stores, Properties properties) throws IOException {
File clusterXml = new File(TestUtils.createTempDir(), "cluster.xml");
File storesXml = new File(TestUtils.createTempDir(), "stores.xml");
ClusterMapper clusterMapper = new ClusterMapper();
StoreDefinitionsMapper storeDefMapper = new StoreDefinitionsMapper();
FileWriter writer = new FileWriter(clusterXml);
writer.write(clusterMapper.writeCluster(cluster));
writer.close();
writer = new FileWriter(storesXml);
writer.write(storeDefMapper.writeStoreList(stores));
writer.close();
return createServerConfig(useNio, nodeId, baseDir, clusterXml.getAbsolutePath(), storesXml.getAbsolutePath(), properties);
}
use of voldemort.xml.ClusterMapper in project voldemort by voldemort.
the class ServerJVMTestUtils method createAndInitializeVoldemortHome.
public static String createAndInitializeVoldemortHome(boolean useNio, int node, String storesXmlfile, Cluster cluster) throws IOException {
VoldemortConfig config = ServerTestUtils.createServerConfig(useNio, node, TestUtils.createTempDir().getAbsolutePath(), null, storesXmlfile, new Properties());
// Initialize voldemort config dir with all required files.
// cluster.xml
File clusterXml = new File(config.getMetadataDirectory() + File.separator + "cluster.xml");
FileUtils.writeStringToFile(clusterXml, new ClusterMapper().writeCluster(cluster));
// stores.xml
File storesXml = new File(config.getMetadataDirectory() + File.separator + "stores.xml");
FileUtils.copyFile(new File(storesXmlfile), storesXml);
// server.properties
File serverProperties = new File(config.getMetadataDirectory() + File.separator + "server.properties");
FileUtils.writeLines(serverProperties, Arrays.asList("node.id=" + node, "bdb.cache.size=" + 1024 * 1024, "enable.metadata.checking=" + false, "enable.network.classloader=" + false));
return config.getVoldemortHome();
}
use of voldemort.xml.ClusterMapper in project voldemort by voldemort.
the class AdminServiceBasicTest method testIsClusterModified.
@Test
public void testIsClusterModified() {
AdminClient client = getAdminClient();
assertFalse("Newly Created admin client has valid cluster", client.isClusterModified());
String clusterXml = new ClusterMapper().writeCluster(cluster);
client.metadataMgmtOps.updateRemoteMetadata(cluster.getNodeIds(), MetadataStore.CLUSTER_KEY, clusterXml);
assertTrue("After cluster update", client.isClusterModified());
}
Aggregations