use of org.apache.pulsar.metadata.api.MetadataCache in project pulsar by yahoo.
the class MetadataCacheTest method testCloneInReadModifyUpdateOrCreate.
@Test(dataProvider = "impl")
public void testCloneInReadModifyUpdateOrCreate(String provider, Supplier<String> urlSupplier) throws Exception {
@Cleanup MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
MetadataCache<Policies> objCache = store.getMetadataCache(Policies.class);
String path = "/testCloneInReadModifyUpdateOrCreate-policies";
// init cache
Policies policies = new Policies();
policies.max_unacked_messages_per_consumer = 100;
objCache.create(path, policies).get();
Policies tempPolicies = objCache.get(path).get().get();
assertSame(tempPolicies, objCache.get(path).get().get());
AtomicReference<Policies> reference = new AtomicReference<>(new Policies());
AtomicReference<Policies> reference2 = new AtomicReference<>(new Policies());
objCache.readModifyUpdateOrCreate(path, (policies1) -> {
Policies policiesRef = policies1.get();
assertNotSame(policiesRef, tempPolicies);
reference.set(policiesRef);
policiesRef.max_unacked_messages_per_consumer = 200;
return policiesRef;
}).get();
objCache.readModifyUpdateOrCreate(path, (policies1) -> {
Policies policiesRef = policies1.get();
assertNotSame(policiesRef, tempPolicies);
reference2.set(policiesRef);
policiesRef.max_unacked_messages_per_consumer = 300;
return policiesRef;
}).get();
// The original object should not be modified
assertEquals(tempPolicies.max_unacked_messages_per_consumer.intValue(), 100);
assertNotSame(reference.get(), reference2.get());
assertNotEquals(reference.get().max_unacked_messages_per_consumer, reference2.get().max_unacked_messages_per_consumer);
}
use of org.apache.pulsar.metadata.api.MetadataCache in project pulsar by yahoo.
the class MetadataCacheTest method crossStoreAddDelete.
@Test(dataProvider = "zk")
public void crossStoreAddDelete(String provider, Supplier<String> urlSupplier) throws Exception {
@Cleanup MetadataStore store1 = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
@Cleanup MetadataStore store2 = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
@Cleanup MetadataStore store3 = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
MetadataCache<MyClass> objCache1 = store1.getMetadataCache(MyClass.class);
MetadataCache<MyClass> objCache2 = store2.getMetadataCache(MyClass.class);
MetadataCache<MyClass> objCache3 = store3.getMetadataCache(MyClass.class);
List<MetadataCache<MyClass>> allCaches = new ArrayList<>();
allCaches.add(objCache1);
allCaches.add(objCache2);
allCaches.add(objCache3);
// Add on one cache and remove from another
multiStoreAddDelete(allCaches, 0, 1, "add cache0 del cache1");
// retry same order to rule out any stale state
multiStoreAddDelete(allCaches, 0, 1, "add cache0 del cache1");
// Reverse the operations
multiStoreAddDelete(allCaches, 1, 0, "add cache1 del cache0");
// Ensure that working on same cache continues to work.
multiStoreAddDelete(allCaches, 1, 1, "add cache1 del cache1");
}
use of org.apache.pulsar.metadata.api.MetadataCache in project incubator-pulsar by apache.
the class MetadataCacheTest method crossStoreAddDelete.
@Test(dataProvider = "zk")
public void crossStoreAddDelete(String provider, Supplier<String> urlSupplier) throws Exception {
@Cleanup MetadataStore store1 = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
@Cleanup MetadataStore store2 = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
@Cleanup MetadataStore store3 = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
MetadataCache<MyClass> objCache1 = store1.getMetadataCache(MyClass.class);
MetadataCache<MyClass> objCache2 = store2.getMetadataCache(MyClass.class);
MetadataCache<MyClass> objCache3 = store3.getMetadataCache(MyClass.class);
List<MetadataCache<MyClass>> allCaches = new ArrayList<>();
allCaches.add(objCache1);
allCaches.add(objCache2);
allCaches.add(objCache3);
// Add on one cache and remove from another
multiStoreAddDelete(allCaches, 0, 1, "add cache0 del cache1");
// retry same order to rule out any stale state
multiStoreAddDelete(allCaches, 0, 1, "add cache0 del cache1");
// Reverse the operations
multiStoreAddDelete(allCaches, 1, 0, "add cache1 del cache0");
// Ensure that working on same cache continues to work.
multiStoreAddDelete(allCaches, 1, 1, "add cache1 del cache1");
}
use of org.apache.pulsar.metadata.api.MetadataCache in project incubator-pulsar by apache.
the class MetadataCacheTest method testReadCloned.
@Test(dataProvider = "impl")
public void testReadCloned(String provider, Supplier<String> urlSupplier) throws Exception {
@Cleanup MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
MetadataCache<Policies> objCache = store.getMetadataCache(Policies.class);
String path = "/testReadCloned-policies";
// init cache
Policies policies = new Policies();
policies.max_unacked_messages_per_consumer = 100;
policies.replication_clusters.add("1");
objCache.create(path, policies).get();
Policies tempPolicies = objCache.get(path).get().get();
assertSame(tempPolicies, objCache.get(path).get().get());
AtomicReference<Policies> reference = new AtomicReference<>(new Policies());
AtomicReference<Policies> reference2 = new AtomicReference<>(new Policies());
objCache.readModifyUpdate(path, (policies1) -> {
assertNotSame(policies1, tempPolicies);
reference.set(policies1);
policies1.max_unacked_messages_per_consumer = 200;
return policies1;
}).get();
objCache.readModifyUpdate(path, (policies1) -> {
assertNotSame(policies1, tempPolicies);
reference2.set(policies1);
policies1.max_unacked_messages_per_consumer = 300;
return policies1;
}).get();
// The original object should not be modified
assertEquals(tempPolicies.max_unacked_messages_per_consumer.intValue(), 100);
assertNotSame(reference.get(), reference2.get());
assertNotEquals(reference.get().max_unacked_messages_per_consumer, reference2.get().max_unacked_messages_per_consumer);
}
use of org.apache.pulsar.metadata.api.MetadataCache in project incubator-pulsar by apache.
the class MetadataCacheTest method testCloneInReadModifyUpdateOrCreate.
@Test(dataProvider = "impl")
public void testCloneInReadModifyUpdateOrCreate(String provider, Supplier<String> urlSupplier) throws Exception {
@Cleanup MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
MetadataCache<Policies> objCache = store.getMetadataCache(Policies.class);
String path = "/testCloneInReadModifyUpdateOrCreate-policies";
// init cache
Policies policies = new Policies();
policies.max_unacked_messages_per_consumer = 100;
objCache.create(path, policies).get();
Policies tempPolicies = objCache.get(path).get().get();
assertSame(tempPolicies, objCache.get(path).get().get());
AtomicReference<Policies> reference = new AtomicReference<>(new Policies());
AtomicReference<Policies> reference2 = new AtomicReference<>(new Policies());
objCache.readModifyUpdateOrCreate(path, (policies1) -> {
Policies policiesRef = policies1.get();
assertNotSame(policiesRef, tempPolicies);
reference.set(policiesRef);
policiesRef.max_unacked_messages_per_consumer = 200;
return policiesRef;
}).get();
objCache.readModifyUpdateOrCreate(path, (policies1) -> {
Policies policiesRef = policies1.get();
assertNotSame(policiesRef, tempPolicies);
reference2.set(policiesRef);
policiesRef.max_unacked_messages_per_consumer = 300;
return policiesRef;
}).get();
// The original object should not be modified
assertEquals(tempPolicies.max_unacked_messages_per_consumer.intValue(), 100);
assertNotSame(reference.get(), reference2.get());
assertNotEquals(reference.get().max_unacked_messages_per_consumer, reference2.get().max_unacked_messages_per_consumer);
}
Aggregations