Search in sources :

Example 1 with ResourceQuota

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");
}
Also used : PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) ResourceQuota(com.yahoo.pulsar.common.policies.data.ResourceQuota) ResourceQuotas(com.yahoo.pulsar.client.admin.ResourceQuotas) Test(org.testng.annotations.Test)

Example 2 with ResourceQuota

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);
}
Also used : ResourceQuota(com.yahoo.pulsar.common.policies.data.ResourceQuota) Test(org.testng.annotations.Test)

Example 3 with ResourceQuota

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);
}
Also used : Policies(com.yahoo.pulsar.common.policies.data.Policies) ResourceQuota(com.yahoo.pulsar.common.policies.data.ResourceQuota) PropertyAdmin(com.yahoo.pulsar.common.policies.data.PropertyAdmin) RestException(com.yahoo.pulsar.broker.web.RestException) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 4 with ResourceQuota

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);
}
Also used : ResourceQuotaCache(com.yahoo.pulsar.broker.cache.ResourceQuotaCache) NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) ResourceQuota(com.yahoo.pulsar.common.policies.data.ResourceQuota) Test(org.testng.annotations.Test)

Example 5 with ResourceQuota

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;
}
Also used : Field(java.lang.reflect.Field) ResourceQuota(com.yahoo.pulsar.common.policies.data.ResourceQuota) AtomicReference(java.util.concurrent.atomic.AtomicReference) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

ResourceQuota (com.yahoo.pulsar.common.policies.data.ResourceQuota)19 Test (org.testng.annotations.Test)9 HashMap (java.util.HashMap)7 Map (java.util.Map)7 TreeMap (java.util.TreeMap)6 ResourceUnit (com.yahoo.pulsar.broker.loadbalance.ResourceUnit)3 LoadReport (com.yahoo.pulsar.common.policies.data.loadbalancer.LoadReport)3 ResourceUnitRanking (com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUnitRanking)3 SystemResourceUsage (com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage)3 ResourceQuotaCache (com.yahoo.pulsar.broker.cache.ResourceQuotaCache)2 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)2 NamespaceBundleStats (com.yahoo.pulsar.common.policies.data.loadbalancer.NamespaceBundleStats)2 ResourceUsage (com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage)2 HashSet (java.util.HashSet)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 PulsarServerException (com.yahoo.pulsar.broker.PulsarServerException)1 MockedPulsarServiceBaseTest (com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)1 SimpleResourceUnit (com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit)1 RestException (com.yahoo.pulsar.broker.web.RestException)1 PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)1