use of com.yahoo.pulsar.common.policies.data.ResourceQuota in project pulsar by yahoo.
the class PulsarAdminToolTest method resourceQuotas.
@Test
void resourceQuotas() throws Exception {
PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
ResourceQuotas mockResourceQuotas = mock(ResourceQuotas.class);
when(admin.resourceQuotas()).thenReturn(mockResourceQuotas);
CmdResourceQuotas cmdResourceQuotas = new CmdResourceQuotas(admin);
ResourceQuota quota = new ResourceQuota();
quota.setMsgRateIn(10);
quota.setMsgRateOut(20);
quota.setBandwidthIn(10000);
quota.setBandwidthOut(20000);
quota.setMemory(100);
quota.setDynamic(false);
cmdResourceQuotas.run(split("get"));
verify(mockResourceQuotas).getDefaultResourceQuota();
cmdResourceQuotas.run(split("set -mi 10 -mo 20 -bi 10000 -bo 20000 -mem 100"));
verify(mockResourceQuotas).setDefaultResourceQuota(quota);
// reset mocks
mockResourceQuotas = mock(ResourceQuotas.class);
when(admin.resourceQuotas()).thenReturn(mockResourceQuotas);
cmdResourceQuotas = new CmdResourceQuotas(admin);
cmdResourceQuotas.run(split("get --namespace myprop/clust/ns1 --bundle 0x80000000_0xffffffff"));
verify(mockResourceQuotas).getNamespaceBundleResourceQuota("myprop/clust/ns1", "0x80000000_0xffffffff");
cmdResourceQuotas.run(split("set --namespace myprop/clust/ns1 --bundle 0x80000000_0xffffffff -mi 10 -mo 20 -bi 10000 -bo 20000 -mem 100"));
verify(mockResourceQuotas).setNamespaceBundleResourceQuota("myprop/clust/ns1", "0x80000000_0xffffffff", quota);
cmdResourceQuotas.run(split("reset-namespace-bundle-quota --namespace myprop/clust/ns1 --bundle 0x80000000_0xffffffff"));
verify(mockResourceQuotas).resetNamespaceBundleResourceQuota("myprop/clust/ns1", "0x80000000_0xffffffff");
}
use of com.yahoo.pulsar.common.policies.data.ResourceQuota in project pulsar by yahoo.
the class ResourceQuotaTest method testResourceQuotaEqual.
@Test
public void testResourceQuotaEqual() {
ResourceQuota quota1 = new ResourceQuota();
quota1.setMsgRateIn(10);
quota1.setMsgRateOut(20);
quota1.setBandwidthIn(10000);
quota1.setBandwidthOut(20000);
quota1.setMemory(100);
quota1.setDynamic(false);
ResourceQuota quota2 = new ResourceQuota();
Assert.assertNotEquals(quota1, quota2);
quota2.setMsgRateIn(10);
Assert.assertNotEquals(quota1, quota2);
quota2.setMsgRateOut(20);
Assert.assertNotEquals(quota1, quota2);
quota2.setBandwidthIn(10000);
Assert.assertNotEquals(quota1, quota2);
quota2.setBandwidthOut(20000);
Assert.assertNotEquals(quota1, quota2);
quota2.setMemory(100);
Assert.assertNotEquals(quota1, quota2);
quota2.setDynamic(false);
Assert.assertEquals(quota1, quota2);
}
use of com.yahoo.pulsar.common.policies.data.ResourceQuota in project pulsar by yahoo.
the class AdminTest method resourceQuotas.
@Test
void resourceQuotas() throws Exception {
// get Default Resource Quota
ResourceQuota quota = resourceQuotas.getDefaultResourceQuota();
assertNotNull(quota);
assertTrue(quota.getBandwidthIn() > 0);
// set Default Resource Quota
double defaultBandwidth = 1000;
quota.setBandwidthIn(defaultBandwidth);
quota.setBandwidthOut(defaultBandwidth);
resourceQuotas.setDefaultResourceQuota(quota);
assertTrue(resourceQuotas.getDefaultResourceQuota().getBandwidthIn() == defaultBandwidth);
assertTrue(resourceQuotas.getDefaultResourceQuota().getBandwidthOut() == defaultBandwidth);
String property = "prop-xyz";
String cluster = "use";
String namespace = "ns";
String bundleRange = "0x00000000_0xffffffff";
Policies policies = new Policies();
doReturn(policies).when(resourceQuotas).getNamespacePolicies(property, cluster, namespace);
doReturn("client-id").when(resourceQuotas).clientAppId();
try {
resourceQuotas.setNamespaceBundleResourceQuota(property, cluster, namespace, bundleRange, quota);
fail();
} catch (Exception e) {
// OK : should fail without creating policies
}
try {
resourceQuotas.removeNamespaceBundleResourceQuota(property, cluster, namespace, bundleRange);
fail();
} catch (Exception e) {
// OK : should fail without creating policies
}
// create policies
PropertyAdmin admin = new PropertyAdmin();
admin.getAllowedClusters().add(cluster);
mockZookKeeper.create(PulsarWebResource.path("policies", property), ObjectMapperFactory.getThreadLocal().writeValueAsBytes(admin), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
// customized bandwidth for this namespace
double customizeBandwidth = 3000;
quota.setBandwidthIn(customizeBandwidth);
quota.setBandwidthOut(customizeBandwidth);
// set and get Resource Quota
resourceQuotas.setNamespaceBundleResourceQuota(property, cluster, namespace, bundleRange, quota);
ResourceQuota bundleQuota = resourceQuotas.getNamespaceBundleResourceQuota(property, cluster, namespace, bundleRange);
assertEquals(quota, bundleQuota);
// remove quota which sets to default quota
resourceQuotas.removeNamespaceBundleResourceQuota(property, cluster, namespace, bundleRange);
bundleQuota = resourceQuotas.getNamespaceBundleResourceQuota(property, cluster, namespace, bundleRange);
assertTrue(bundleQuota.getBandwidthIn() == defaultBandwidth);
assertTrue(bundleQuota.getBandwidthOut() == defaultBandwidth);
}
use of com.yahoo.pulsar.common.policies.data.ResourceQuota in project pulsar by yahoo.
the class ResourceQuotaCacheTest method testGetSetBundleQuota.
@Test
public void testGetSetBundleQuota() throws Exception {
ResourceQuotaCache cache = new ResourceQuotaCache(zkCache);
NamespaceBundle testBundle = bundleFactory.getFullBundle(new NamespaceName("pulsar/test/ns-2"));
ResourceQuota quota1 = ResourceQuotaCache.getInitialQuotaValue();
ResourceQuota quota2 = new ResourceQuota();
quota2.setMsgRateIn(10);
quota2.setMsgRateOut(20);
quota2.setBandwidthIn(10000);
quota2.setBandwidthOut(20000);
quota2.setMemory(100);
quota2.setDynamic(false);
assertEquals(cache.getQuota(testBundle), quota1);
cache.setQuota(testBundle, quota2);
assertEquals(cache.getQuota(testBundle), quota2);
cache.unsetQuota(testBundle);
assertEquals(cache.getQuota(testBundle), quota1);
}
use of com.yahoo.pulsar.common.policies.data.ResourceQuota in project pulsar by yahoo.
the class LoadBalancerTest method getRealtimeResourceQuota.
private AtomicReference<Map<String, ResourceQuota>> getRealtimeResourceQuota(PulsarService pulsar) throws NoSuchFieldException, IllegalAccessException {
Field quotasField = ((SimpleLoadManagerImpl) pulsar.getLoadManager()).getClass().getDeclaredField("realtimeResourceQuotas");
quotasField.setAccessible(true);
AtomicReference<Map<String, ResourceQuota>> realtimeResourceQuotas = (AtomicReference<Map<String, ResourceQuota>>) quotasField.get(pulsar.getLoadManager());
return realtimeResourceQuotas;
}
Aggregations