Search in sources :

Example 1 with BytesPushThroughSerializer

use of org.I0Itec.zkclient.serialize.BytesPushThroughSerializer in project curator by Netflix.

the class ZkClientSerializationTest method testBytes.

@Test
public void testBytes() throws Exception {
    ZkClient zkClient = ZkTestSystem.createZkClient(_zk.getZkServerAddress());
    zkClient.setZkSerializer(new BytesPushThroughSerializer());
    byte[] bytes = new byte[100];
    new Random().nextBytes(bytes);
    zkClient.createPersistent("/a", bytes);
    byte[] readBytes = zkClient.readData("/a");
    assertArrayEquals(bytes, readBytes);
}
Also used : BytesPushThroughSerializer(org.I0Itec.zkclient.serialize.BytesPushThroughSerializer) Random(java.util.Random) Test(org.junit.Test)

Example 2 with BytesPushThroughSerializer

use of org.I0Itec.zkclient.serialize.BytesPushThroughSerializer in project helix by apache.

the class TestEnableCompression method testEnableCompressionResource.

@Test()
public void testEnableCompressionResource() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    MockParticipantManager[] participants = new MockParticipantManager[5];
    // ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
    int numNodes = 10;
    // participant port
    TestHelper.setupCluster(// participant port
    clusterName, // participant port
    ZK_ADDR, // participant port
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestDB", // no resources, will be added later
    0, // partitions per resource
    0, // number of nodes
    numNodes, // replicas
    0, "OnlineOffline", // dont rebalance
    false);
    List<String> instancesInCluster = _gSetupTool.getClusterManagementTool().getInstancesInCluster(clusterName);
    String resourceName = "TestResource";
    CustomModeISBuilder customModeISBuilder = new CustomModeISBuilder(resourceName);
    int numPartitions = 10000;
    int numReplica = 3;
    customModeISBuilder.setNumPartitions(numPartitions);
    customModeISBuilder.setNumReplica(numReplica);
    customModeISBuilder.setStateModel("OnlineOffline");
    for (int p = 0; p < numPartitions; p++) {
        String partitionName = resourceName + "_" + p;
        customModeISBuilder.add(partitionName);
        for (int r = 0; r < numReplica; r++) {
            String instanceName = instancesInCluster.get((p % numNodes + r) % numNodes);
            customModeISBuilder.assignInstanceAndState(partitionName, instanceName, "ONLINE");
        }
    }
    IdealState idealstate = customModeISBuilder.build();
    idealstate.getRecord().setBooleanField("enableCompression", true);
    _gSetupTool.getClusterManagementTool().addResource(clusterName, resourceName, idealstate);
    ZkClient zkClient = new ZkClient(ZK_ADDR, 60 * 1000, 60 * 1000, new BytesPushThroughSerializer());
    zkClient.waitUntilConnected(10, TimeUnit.SECONDS);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    for (int i = 0; i < 5; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName), 120000);
    Assert.assertTrue(result);
    List<String> compressedPaths = new ArrayList<String>();
    findCompressedZNodes(zkClient, "/", compressedPaths);
    System.out.println("compressed paths:" + compressedPaths);
    // ONLY IDEALSTATE and EXTERNAL VIEW must be compressed
    Assert.assertEquals(compressedPaths.size(), 2);
    String idealstatePath = PropertyPathBuilder.idealState(clusterName, resourceName);
    String externalViewPath = PropertyPathBuilder.externalView(clusterName, resourceName);
    Assert.assertTrue(compressedPaths.contains(idealstatePath));
    Assert.assertTrue(compressedPaths.contains(externalViewPath));
    // clean up
    controller.syncStop();
    for (int i = 0; i < 5; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : CustomModeISBuilder(org.apache.helix.model.builder.CustomModeISBuilder) ZkClient(org.apache.helix.manager.zk.ZkClient) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) BytesPushThroughSerializer(org.I0Itec.zkclient.serialize.BytesPushThroughSerializer) ArrayList(java.util.ArrayList) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) IdealState(org.apache.helix.model.IdealState) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) Test(org.testng.annotations.Test)

Aggregations

BytesPushThroughSerializer (org.I0Itec.zkclient.serialize.BytesPushThroughSerializer)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Random (java.util.Random)1 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)1 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)1 ZkClient (org.apache.helix.manager.zk.ZkClient)1 IdealState (org.apache.helix.model.IdealState)1 CustomModeISBuilder (org.apache.helix.model.builder.CustomModeISBuilder)1 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)1 Test (org.junit.Test)1 Test (org.testng.annotations.Test)1