Search in sources :

Example 91 with ZNRecord

use of org.apache.helix.ZNRecord in project helix by apache.

the class TestZkHelixAdmin method testLegacyEnableDisablePartition.

@Test
public void testLegacyEnableDisablePartition() {
    String instanceName = "TestInstanceLegacy";
    String testResourcePrefix = "TestResourceLegacy";
    ZNRecord record = new ZNRecord(instanceName);
    List<String> disabledPartitions = new ArrayList<String>(Arrays.asList(new String[] { "1", "2", "3" }));
    record.setListField(InstanceConfig.InstanceConfigProperty.HELIX_DISABLED_PARTITION.name(), disabledPartitions);
    InstanceConfig instanceConfig = new InstanceConfig(record);
    instanceConfig.setInstanceEnabledForPartition(testResourcePrefix, "2", false);
    Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix).size(), 3);
    Assert.assertEquals(instanceConfig.getRecord().getListField(InstanceConfig.InstanceConfigProperty.HELIX_DISABLED_PARTITION.name()).size(), 3);
    instanceConfig.setInstanceEnabledForPartition(testResourcePrefix, "2", true);
    Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix).size(), 2);
    Assert.assertEquals(instanceConfig.getRecord().getListField(InstanceConfig.InstanceConfigProperty.HELIX_DISABLED_PARTITION.name()).size(), 2);
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) ArrayList(java.util.ArrayList) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 92 with ZNRecord

use of org.apache.helix.ZNRecord in project helix by apache.

the class TestJacksonPayloadSerializer method testFullZNRecordStreamingSerializeDeserialize.

/**
 * Test that the payload can be deserialized after serializing and deserializing the ZNRecord
 * that encloses it. This uses ZNRecordStreamingSerializer.
 */
@Test
public void testFullZNRecordStreamingSerializeDeserialize() {
    final String RECORD_ID = "testFullZNRecordStreamingSerializeDeserialize";
    SampleDeserialized sample = getSample();
    ZNRecord znRecord = new ZNRecord(RECORD_ID);
    znRecord.setPayloadSerializer(new JacksonPayloadSerializer());
    znRecord.setPayload(sample);
    ZNRecordStreamingSerializer znRecordSerializer = new ZNRecordStreamingSerializer();
    byte[] serialized = znRecordSerializer.serialize(znRecord);
    ZNRecord deserialized = (ZNRecord) znRecordSerializer.deserialize(serialized);
    deserialized.setPayloadSerializer(new JacksonPayloadSerializer());
    SampleDeserialized duplicate = deserialized.getPayload(SampleDeserialized.class);
    Assert.assertEquals(duplicate, sample);
}
Also used : ZNRecordStreamingSerializer(org.apache.helix.manager.zk.ZNRecordStreamingSerializer) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 93 with ZNRecord

use of org.apache.helix.ZNRecord in project helix by apache.

the class TestJacksonPayloadSerializer method testRawPayloadMissingIfUnspecified.

/**
 * Test that the payload is not included whenever it is not null. This is mainly to maintain
 * backward
 * compatibility.
 */
@Test
public void testRawPayloadMissingIfUnspecified() {
    final String RECORD_ID = "testRawPayloadMissingIfUnspecified";
    ZNRecord znRecord = new ZNRecord(RECORD_ID);
    ZNRecordSerializer znRecordSerializer = new ZNRecordSerializer();
    byte[] serialized = znRecordSerializer.serialize(znRecord);
    ZNRecordStreamingSerializer znRecordStreamingSerializer = new ZNRecordStreamingSerializer();
    byte[] streamingSerialized = znRecordStreamingSerializer.serialize(znRecord);
    ObjectMapper mapper = new ObjectMapper();
    try {
        JsonNode jsonNode = mapper.readTree(new String(serialized));
        Assert.assertFalse(jsonNode.has("rawPayload"));
        JsonNode streamingJsonNode = mapper.readTree(new String(streamingSerialized));
        Assert.assertFalse(streamingJsonNode.has("rawPayload"));
    } catch (JsonProcessingException e) {
        Assert.fail();
    } catch (IOException e) {
        Assert.fail();
    }
}
Also used : ZNRecordStreamingSerializer(org.apache.helix.manager.zk.ZNRecordStreamingSerializer) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) ZNRecord(org.apache.helix.ZNRecord) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) Test(org.testng.annotations.Test)

Example 94 with ZNRecord

use of org.apache.helix.ZNRecord in project helix by apache.

the class TestJacksonPayloadSerializer method testJacksonSerializeDeserialize.

/**
 * Ensure that the JacksonPayloadSerializer can serialize and deserialize arbitrary objects
 */
@Test
public void testJacksonSerializeDeserialize() {
    final String RECORD_ID = "testJacksonSerializeDeserialize";
    SampleDeserialized sample = getSample();
    ZNRecord znRecord = new ZNRecord(RECORD_ID);
    znRecord.setPayloadSerializer(new JacksonPayloadSerializer());
    znRecord.setPayload(sample);
    SampleDeserialized duplicate = znRecord.getPayload(SampleDeserialized.class);
    Assert.assertEquals(duplicate, sample);
}
Also used : ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 95 with ZNRecord

use of org.apache.helix.ZNRecord in project helix by apache.

the class TestWtCacheSyncOpSingleThread method testCreateFailZkCacheBaseDataAccessor.

@Test
public void testCreateFailZkCacheBaseDataAccessor() {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // init zkCacheDataAccessor
    String curStatePath = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901");
    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
    ZkCacheBaseDataAccessor<ZNRecord> accessor = new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, Arrays.asList(curStatePath), null);
    // create 10 current states
    for (int i = 0; i < 10; i++) {
        String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901", "session_1", "TestDB" + i);
        boolean success = accessor.create(path, new ZNRecord("TestDB" + i), AccessOption.PERSISTENT);
        Assert.assertTrue(success, "Should succeed in create: " + path);
    }
    // create same 10 current states again, should fail
    for (int i = 0; i < 10; i++) {
        String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901", "session_1", "TestDB" + i);
        boolean success = accessor.create(path, new ZNRecord("TestDB" + i), AccessOption.PERSISTENT);
        Assert.assertFalse(success, "Should fail in create due to NodeExists: " + path);
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : Date(java.util.Date) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Aggregations

ZNRecord (org.apache.helix.ZNRecord)448 Test (org.testng.annotations.Test)186 ArrayList (java.util.ArrayList)117 Date (java.util.Date)111 HelixDataAccessor (org.apache.helix.HelixDataAccessor)91 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)78 Builder (org.apache.helix.PropertyKey.Builder)75 HashMap (java.util.HashMap)72 IdealState (org.apache.helix.model.IdealState)69 PropertyKey (org.apache.helix.PropertyKey)61 HelixException (org.apache.helix.HelixException)47 Map (java.util.Map)41 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)40 ZkBaseDataAccessor (org.apache.helix.manager.zk.ZkBaseDataAccessor)40 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)33 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)30 List (java.util.List)29 ZkClient (org.apache.helix.manager.zk.ZkClient)29 HelixAdmin (org.apache.helix.HelixAdmin)28 LiveInstance (org.apache.helix.model.LiveInstance)28