aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [1/2] Client quota checks. Part 2: server side changes.
Date Wed, 15 Jan 2014 21:06:17 GMT
Updated Branches:
  refs/heads/master a6ab7fdb7 -> e2b357e7f


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/e2b357e7/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
index b46f29a..6cefdfa 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
@@ -70,6 +70,8 @@ import org.apache.aurora.scheduler.base.Query;
 import org.apache.aurora.scheduler.base.ScheduleException;
 import org.apache.aurora.scheduler.configuration.ConfigurationManager;
 import org.apache.aurora.scheduler.configuration.SanitizedConfiguration;
+import org.apache.aurora.scheduler.quota.QuotaInfo;
+import org.apache.aurora.scheduler.quota.QuotaManager;
 import org.apache.aurora.scheduler.state.CronJobManager;
 import org.apache.aurora.scheduler.state.LockManager;
 import org.apache.aurora.scheduler.state.LockManager.LockException;
@@ -125,6 +127,8 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
   private static final ILock LOCK = ILock.build(new Lock().setKey(LOCK_KEY.newBuilder()));
   private static final JobConfiguration CRON_JOB = makeJob().setCronSchedule("test");
   private static final Lock DEFAULT_LOCK = null;
+  private static final IQuota QUOTA = IQuota.build(new Quota(10.0, 1024, 2048));
+  private static final IQuota CONSUMED = IQuota.build(new Quota(0.0, 0, 0));
 
   private StorageTestUtil storageUtil;
   private SchedulerCore scheduler;
@@ -136,6 +140,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
   private MaintenanceController maintenance;
   private AuroraAdmin.Iface thrift;
   private CronJobManager cronJobManager;
+  private QuotaManager quotaManager;
 
   @Before
   public void setUp() throws Exception {
@@ -150,6 +155,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     recovery = createMock(Recovery.class);
     maintenance = createMock(MaintenanceController.class);
     cronJobManager = createMock(CronJobManager.class);
+    quotaManager = createMock(QuotaManager.class);
 
     // Use guice and install AuthModule to apply AOP-style auth layer.
     Module testModule = new AbstractModule() {
@@ -163,6 +169,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
         bind(Recovery.class).toInstance(recovery);
         bind(MaintenanceController.class).toInstance(maintenance);
         bind(CronJobManager.class).toInstance(cronJobManager);
+        bind(QuotaManager.class).toInstance(quotaManager);
         bind(AuroraAdmin.Iface.class).to(SchedulerThriftInterface.class);
       }
     };
@@ -194,7 +201,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
   }
 
   @Test
-  public void testPopulateJobConfigFailFilter() throws Exception {
+  public void testPopulateJobConfigFailQuotaCheck() throws Exception {
     IJobConfiguration job = IJobConfiguration.build(makeJob());
     scheduler.validateJobResources(anyObject(SanitizedConfiguration.class));
     expectLastCall().andThrow(new ScheduleException("err"));
@@ -430,7 +437,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
         .setDiskMb(100)
         .setRamMb(200);
     expectAuth(ROOT, true);
-    storageUtil.quotaStore.saveQuota(ROLE, IQuota.build(quota));
+    quotaManager.saveQuota(ROLE, IQuota.build(quota));
 
     control.replay();
 
@@ -439,6 +446,22 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
   }
 
   @Test
+  public void testSetQuotaFails() throws Exception {
+    Quota quota = new Quota()
+        .setNumCpus(10)
+        .setDiskMb(100)
+        .setRamMb(200);
+    expectAuth(ROOT, true);
+    quotaManager.saveQuota(ROLE, IQuota.build(quota));
+    expectLastCall().andThrow(new QuotaManager.QuotaException("fail"));
+
+    control.replay();
+
+    Response response = thrift.setQuota(ROLE, quota, SESSION);
+    assertEquals(ResponseCode.INVALID_REQUEST, response.getResponseCode());
+  }
+
+  @Test
   public void testProvisionerSetQuota() throws Exception {
     Quota quota = new Quota()
         .setNumCpus(10)
@@ -446,7 +469,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
         .setRamMb(200);
     expectAuth(ROOT, false);
     expectAuth(Capability.PROVISIONER, true);
-    storageUtil.quotaStore.saveQuota(ROLE, IQuota.build(quota));
+    quotaManager.saveQuota(ROLE, IQuota.build(quota));
 
     control.replay();
 
@@ -1319,6 +1342,20 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     assertEquals(ResponseCode.LOCK_ERROR, response.getResponseCode());
   }
 
+  @Test
+  public void testGetQuota() throws Exception {
+    QuotaInfo infoMock = createMock(QuotaInfo.class);
+    expect(quotaManager.getQuotaInfo(ROLE)).andReturn(infoMock);
+    expect(infoMock.guota()).andReturn(QUOTA);
+    expect(infoMock.prodConsumption()).andReturn(CONSUMED);
+    control.replay();
+
+    Response response = thrift.getQuota(ROLE);
+    assertEquals(ResponseCode.OK, response.getResponseCode());
+    assertEquals(QUOTA.newBuilder(), response.getResult().getGetQuotaResult().getQuota());
+    assertEquals(CONSUMED.newBuilder(), response.getResult().getGetQuotaResult().getConsumed());
+  }
+
   private static JobConfiguration makeJob() {
     return makeJob(nonProductionTask(), 1);
   }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/e2b357e7/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java b/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
index cce27a0..644d6e8 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
@@ -34,6 +34,7 @@ import org.apache.aurora.gen.AuroraAdmin;
 import org.apache.aurora.gen.Quota;
 import org.apache.aurora.gen.SessionKey;
 import org.apache.aurora.scheduler.cron.CronScheduler;
+import org.apache.aurora.scheduler.quota.QuotaManager;
 import org.apache.aurora.scheduler.state.LockManager;
 import org.apache.aurora.scheduler.state.MaintenanceController;
 import org.apache.aurora.scheduler.state.SchedulerCore;
@@ -66,6 +67,7 @@ public class ThriftIT extends EasyMockTest {
   private AuroraAdmin.Iface thrift;
   private StorageTestUtil storageTestUtil;
   private SessionContext context;
+  private QuotaManager quotaManager;
 
   private final SessionValidator validator = new SessionValidator() {
     @Override public SessionContext checkAuthenticated(
@@ -120,6 +122,7 @@ public class ThriftIT extends EasyMockTest {
   @Before
   public void setUp() {
     context = createMock(SessionContext.class);
+    quotaManager = createMock(QuotaManager.class);
     createThrift(CAPABILITIES);
   }
 
@@ -146,6 +149,7 @@ public class ThriftIT extends EasyMockTest {
             bind(Storage.class).toInstance(storageTestUtil.storage);
             bindMock(StorageBackup.class);
             bindMock(ThriftConfiguration.class);
+            bind(QuotaManager.class).toInstance(quotaManager);
             bind(SessionValidator.class).toInstance(validator);
             bind(CapabilityValidator.class).toInstance(new CapabilityValidatorFake(validator));
           }
@@ -163,8 +167,7 @@ public class ThriftIT extends EasyMockTest {
 
   @Test
   public void testProvisionAccess() throws Exception {
-    storageTestUtil.expectOperations();
-    storageTestUtil.quotaStore.saveQuota(USER, QUOTA);
+    quotaManager.saveQuota(USER, QUOTA);
     expectLastCall().times(2);
 
     control.replay();


Mime
View raw message