Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
*/
package org.apache.pulsar.broker.resourcegroup;

import static org.apache.pulsar.broker.cache.ConfigurationCacheService.RESOURCEGROUPS;
import static org.apache.pulsar.common.policies.path.PolicyPath.path;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertThrows;
import com.google.common.collect.Sets;
import java.util.Random;

import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.common.policies.data.ClusterData;
Expand All @@ -34,6 +38,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

@Slf4j
public class ResourceGroupConfigListenerTest extends MockedPulsarServiceBaseTest {

ResourceGroup testAddRg = new ResourceGroup();
Expand Down Expand Up @@ -166,6 +171,51 @@ public void testResourceGroupCreateMany() throws Exception {
});
}

@Test
public void testResourceGroupUpdateLoop() throws PulsarAdminException {

ResourceGroup zooRg = new ResourceGroup();
pulsar.getPulsarResources().getResourcegroupResources().getStore().registerListener(
notification -> {
String notifyPath = notification.getPath();
String rgName = notifyPath.substring(notifyPath.lastIndexOf('/') + 1);
if (!notifyPath.startsWith(path(RESOURCEGROUPS))) {
return;
}
if (RESOURCEGROUPS.equals(rgName)) {
return;
}
pulsar.getPulsarResources().getResourcegroupResources()
.getAsync(notifyPath).whenComplete((optionalRg, ex) -> {
if (ex != null) {
return;
}
if (optionalRg.isPresent()) {
ResourceGroup resourceGroup = optionalRg.get();

zooRg.setDispatchRateInBytes(resourceGroup.getDispatchRateInBytes());
zooRg.setDispatchRateInMsgs(resourceGroup.getDispatchRateInMsgs());
zooRg.setPublishRateInBytes(resourceGroup.getPublishRateInBytes());
zooRg.setPublishRateInMsgs(resourceGroup.getPublishRateInMsgs());
}
});
}
);
ResourceGroup rg = new ResourceGroup();
rg.setPublishRateInMsgs(-1);
rg.setPublishRateInBytes(10);
rg.setDispatchRateInMsgs(10);
rg.setDispatchRateInBytes(20);
createResourceGroup("myrg", rg);

for (int i = 0; i < 1000; i++) {
rg.setPublishRateInMsgs(i);
updateResourceGroup("myrg", rg);
}

Awaitility.await().untilAsserted(() -> assertEquals(zooRg.getPublishRateInMsgs(), rg.getPublishRateInMsgs()));
}

private void prepareData() throws PulsarAdminException {
admin.clusters().createCluster(clusterName, ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ public CompletableFuture<T> readModifyUpdateOrCreate(String path, Function<Optio

return store.put(path, newValue, Optional.of(expectedVersion)).thenAccept(stat -> {
// Make sure we have the value cached before the operation is completed
objCache.put(path,
FutureUtils.value(Optional.of(new CacheGetResult<>(newValueObj, stat))));
//objCache.put(path,
// FutureUtils.value(Optional.of(new CacheGetResult<>(newValueObj, stat))));
}).thenApply(__ -> newValueObj);
}), path);
}
Expand Down Expand Up @@ -192,8 +192,8 @@ public CompletableFuture<T> readModifyUpdate(String path, Function<T, T> modifyF

return store.put(path, newValue, Optional.of(expectedVersion)).thenAccept(stat -> {
// Make sure we have the value cached before the operation is completed
objCache.put(path,
FutureUtils.value(Optional.of(new CacheGetResult<>(newValueObj, stat))));
//objCache.put(path,
// FutureUtils.value(Optional.of(new CacheGetResult<>(newValueObj, stat))));
}).thenApply(__ -> newValueObj);
}), path);
}
Expand Down