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