aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject [1/2] incubator-aurora git commit: Remove ReadWriteLock from MemStorage, remove Storage#weaklyConsistentRead.
Date Fri, 21 Nov 2014 23:44:05 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master ecc3fbcac -> 5116c2209


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/5116c220/src/test/java/org/apache/aurora/scheduler/storage/db/DbQuotaStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/db/DbQuotaStoreTest.java b/src/test/java/org/apache/aurora/scheduler/storage/db/DbQuotaStoreTest.java
index 6d8d52a..dc27c3e 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/db/DbQuotaStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/db/DbQuotaStoreTest.java
@@ -97,7 +97,7 @@ public class DbQuotaStoreTest {
   }
 
   private Optional<IResourceAggregate> select(final String role) {
-    return storage.consistentRead(new Work.Quiet<Optional<IResourceAggregate>>()
{
+    return storage.read(new Work.Quiet<Optional<IResourceAggregate>>() {
       @Override
       public Optional<IResourceAggregate> apply(StoreProvider storeProvider) {
         return storeProvider.getQuotaStore().fetchQuota(role);
@@ -108,7 +108,7 @@ public class DbQuotaStoreTest {
   private void assertQuotas(Map<String, IResourceAggregate> quotas) {
     assertEquals(
         quotas,
-        storage.consistentRead(new Work.Quiet<Map<String, IResourceAggregate>>()
{
+        storage.read(new Work.Quiet<Map<String, IResourceAggregate>>() {
           @Override
           public Map<String, IResourceAggregate> apply(StoreProvider storeProvider)
{
             return storeProvider.getQuotaStore().fetchQuotas();

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/5116c220/src/test/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStoreTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStoreTest.java
index 9c00c8b..0bfb4d4 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStoreTest.java
@@ -55,7 +55,7 @@ public class DbSchedulerStoreTest {
   }
 
   private Optional<String> select() {
-    return storage.consistentRead(new Work.Quiet<Optional<String>>() {
+    return storage.read(new Work.Quiet<Optional<String>>() {
       @Override
       public Optional<String> apply(StoreProvider storeProvider) {
         return storeProvider.getSchedulerStore().fetchFrameworkId();

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/5116c220/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java b/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
index 259c6a9..0a5cc51 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
@@ -16,6 +16,7 @@ package org.apache.aurora.scheduler.storage.log;
 import java.util.EnumSet;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.ReentrantLock;
 
 import com.google.common.base.Function;
 import com.google.common.base.Functions;
@@ -177,7 +178,8 @@ public class LogStorageTest extends EasyMockTest {
         storageUtil.quotaStore,
         storageUtil.attributeStore,
         storageUtil.jobUpdateStore,
-        eventSink);
+        eventSink,
+        new ReentrantLock());
 
     stream = createMock(Stream.class);
     streamMatcher = LogOpMatcher.matcherFor(stream);
@@ -481,7 +483,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws CodingException {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.schedulerStore.saveFrameworkId(frameworkId);
         streamMatcher.expectTransaction(Op.saveFrameworkId(new SaveFrameworkId(frameworkId)))
             .andReturn(position);
@@ -502,7 +504,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.jobStore.saveAcceptedJob(managerId, jobConfig);
         streamMatcher.expectTransaction(
             Op.saveAcceptedJob(new SaveAcceptedJob(managerId, jobConfig.newBuilder())))
@@ -521,7 +523,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.jobStore.removeJob(JOB_KEY);
         streamMatcher.expectTransaction(
             Op.removeJob(new RemoveJob().setJobKey(JOB_KEY.newBuilder())))
@@ -541,7 +543,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.taskStore.saveTasks(tasks);
         streamMatcher.expectTransaction(
             Op.saveTasks(new SaveTasks(IScheduledTask.toBuildersSet(tasks))))
@@ -564,7 +566,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         expect(storageUtil.taskStore.mutateTasks(query, mutation)).andReturn(mutated);
         streamMatcher.expectTransaction(
             Op.saveTasks(new SaveTasks(IScheduledTask.toBuildersSet(mutated))))
@@ -587,7 +589,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         expect(storageUtil.taskStore.unsafeModifyInPlace(taskId2, updatedConfig)).andReturn(false);
         expect(storageUtil.taskStore.unsafeModifyInPlace(taskId, updatedConfig)).andReturn(true);
         streamMatcher.expectTransaction(
@@ -614,7 +616,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         expect(storageUtil.taskStore.mutateTasks(query, mutation)).andReturn(mutated);
 
         storageUtil.taskStore.deleteTasks(tasksToRemove);
@@ -649,7 +651,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.taskStore.saveTasks(saved);
 
         // Nested transaction with result.
@@ -679,7 +681,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.taskStore.saveTasks(saved);
 
         // Nested transaction with result.
@@ -710,7 +712,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.taskStore.deleteTasks(taskIds);
         streamMatcher.expectTransaction(Op.removeTasks(new RemoveTasks(taskIds)))
             .andReturn(position);
@@ -729,7 +731,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.taskStore.deleteTasks(taskIds);
         streamMatcher.expectTransaction(Op.removeTasks(new RemoveTasks(taskIds)))
             .andReturn(position);
@@ -751,7 +753,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.quotaStore.saveQuota(role, quota);
         streamMatcher.expectTransaction(Op.saveQuota(new SaveQuota(role, quota.newBuilder())))
             .andReturn(position);
@@ -770,7 +772,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.quotaStore.removeQuota(role);
         streamMatcher.expectTransaction(Op.removeQuota(new RemoveQuota(role))).andReturn(position);
       }
@@ -792,7 +794,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.lockStore.saveLock(lock);
         streamMatcher.expectTransaction(Op.saveLock(new SaveLock(lock.newBuilder())))
             .andReturn(position);
@@ -812,7 +814,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.lockStore.removeLock(lockKey);
         streamMatcher.expectTransaction(Op.removeLock(new RemoveLock(lockKey.newBuilder())))
             .andReturn(position);
@@ -838,7 +840,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         expect(storageUtil.attributeStore.getHostAttributes(host))
             .andReturn(Optional.<IHostAttributes>absent());
 
@@ -902,7 +904,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.jobUpdateStore.saveJobUpdate(update, lockToken);
         streamMatcher.expectTransaction(
             Op.saveJobUpdate(new SaveJobUpdate(update.newBuilder(), lockToken.orNull())))
@@ -925,7 +927,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.jobUpdateStore.saveJobUpdateEvent(event, UPDATE_ID);
         streamMatcher.expectTransaction(Op.saveJobUpdateEvent(new SaveJobUpdateEvent(
             event.newBuilder(),
@@ -949,7 +951,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         storageUtil.jobUpdateStore.saveJobInstanceUpdateEvent(event, UPDATE_ID);
         streamMatcher.expectTransaction(Op.saveJobInstanceUpdateEvent(
             new SaveJobInstanceUpdateEvent(event.newBuilder(), UPDATE_ID))).andReturn(position);
@@ -971,7 +973,7 @@ public class LogStorageTest extends EasyMockTest {
     new MutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
-        storageUtil.expectWriteOperation();
+        storageUtil.expectWrite();
         expect(storageUtil.jobUpdateStore.pruneHistory(
             pruneHistory.getPerJobRetainCount(),
             pruneHistory.getHistoryPruneThresholdMs())).andReturn(ImmutableSet.of("id1"));

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/5116c220/src/test/java/org/apache/aurora/scheduler/storage/mem/MemStorageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/mem/MemStorageTest.java b/src/test/java/org/apache/aurora/scheduler/storage/mem/MemStorageTest.java
index 463b445..30e2328 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/mem/MemStorageTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/mem/MemStorageTest.java
@@ -45,7 +45,6 @@ import org.apache.aurora.scheduler.storage.Storage.StoreProvider;
 import org.apache.aurora.scheduler.storage.Storage.Work;
 import org.apache.aurora.scheduler.storage.entities.IResourceAggregate;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
-import org.apache.aurora.scheduler.testing.FakeStatsProvider;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -58,7 +57,6 @@ import static org.junit.Assert.fail;
 public class MemStorageTest extends TearDownTestCase {
 
   private ExecutorService executor;
-  private FakeStatsProvider statsProvider;
   private Storage storage;
 
   @Before
@@ -71,8 +69,7 @@ public class MemStorageTest extends TearDownTestCase {
         new ExecutorServiceShutdown(executor, Amount.of(1L, Time.SECONDS)).execute();
       }
     });
-    statsProvider = new FakeStatsProvider();
-    storage = MemStorage.newEmptyStorage(statsProvider);
+    storage = MemStorage.newEmptyStorage();
   }
 
   @Test
@@ -85,7 +82,7 @@ public class MemStorageTest extends TearDownTestCase {
     Future<String> future = executor.submit(new Callable<String>() {
       @Override
       public String call() throws Exception {
-        return storage.consistentRead(new Work.Quiet<String>() {
+        return storage.read(new Work.Quiet<String>() {
           @Override
           public String apply(StoreProvider storeProvider) {
             slowReadStarted.countDown();
@@ -102,7 +99,7 @@ public class MemStorageTest extends TearDownTestCase {
 
     slowReadStarted.await();
 
-    String fastResult = storage.consistentRead(new Work.Quiet<String>() {
+    String fastResult = storage.read(new Work.Quiet<String>() {
       @Override
       public String apply(StoreProvider storeProvider) {
         return "fastResult";
@@ -111,13 +108,6 @@ public class MemStorageTest extends TearDownTestCase {
     assertEquals("fastResult", fastResult);
     slowReadFinished.countDown();
     assertEquals("slowResult", future.get());
-
-    // It would be nice to check the stat values (specifically with simulated lock contention,
but
-    // this value is based off ReentrantReadWriteLock#getQueueLength(), which is documented
as an
-    // approximation and not a guaranteed accurate value.
-    assertEquals(
-        ImmutableSet.of(MemStorage.THREADS_WAITING_GAUGE),
-        statsProvider.getAllValues().keySet());
   }
 
   private IScheduledTask makeTask(String taskId) {
@@ -143,7 +133,7 @@ public class MemStorageTest extends TearDownTestCase {
   }
 
   private void expectTasks(final String... taskIds) {
-    storage.consistentRead(new Work.Quiet<Void>() {
+    storage.read(new Work.Quiet<Void>() {
       @Override
       public Void apply(StoreProvider storeProvider) {
         Query.Builder query = Query.unscoped();
@@ -174,12 +164,12 @@ public class MemStorageTest extends TearDownTestCase {
       // Expected
     }
 
-    storage.consistentRead(new Work.Quiet<Void>() {
+    storage.read(new Work.Quiet<Void>() {
       @Override
       public Void apply(StoreProvider storeProvider) {
         // If the previous write was under a transaction then there would be no quota records.
         assertEquals(ImmutableMap.<String, IResourceAggregate>of(),
-                storeProvider.getQuotaStore().fetchQuotas());
+            storeProvider.getQuotaStore().fetchQuotas());
         return null;
       }
     });
@@ -221,7 +211,7 @@ public class MemStorageTest extends TearDownTestCase {
       }
     });
     expectTasks("a");
-    storage.consistentRead(new Work.Quiet<Void>() {
+    storage.read(new Work.Quiet<Void>() {
       @Override
       public Void apply(StoreProvider storeProvider) {
         assertEquals(

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/5116c220/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageTestUtil.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageTestUtil.java
b/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageTestUtil.java
index 6918cba..d492e17 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageTestUtil.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageTestUtil.java
@@ -73,9 +73,9 @@ public class StorageTestUtil {
     this.storage = easyMock.createMock(NonVolatileStorage.class);
   }
 
-  public <T> IExpectationSetters<T> expectConsistentRead() {
+  public <T> IExpectationSetters<T> expectRead() {
     final Capture<Work<T, RuntimeException>> work = EasyMockTest.createCapture();
-    return expect(storage.<T, RuntimeException>consistentRead(capture(work)))
+    return expect(storage.read(capture(work)))
         .andAnswer(new IAnswer<T>() {
           @Override
           public T answer() {
@@ -84,20 +84,9 @@ public class StorageTestUtil {
         });
   }
 
-  public <T> IExpectationSetters<T> expectWeaklyConsistentRead() {
-    final Capture<Work<T, RuntimeException>> work = EasyMockTest.createCapture();
-    return expect(storage.<T, RuntimeException>weaklyConsistentRead(capture(work)))
-        .andAnswer(new IAnswer<T>() {
-          @Override
-          public T answer() {
-            return work.getValue().apply(storeProvider);
-          }
-        });
-  }
-
-  public <T> IExpectationSetters<T> expectWriteOperation() {
+  public <T> IExpectationSetters<T> expectWrite() {
     final Capture<MutateWork<T, RuntimeException>> work = EasyMockTest.createCapture();
-    return expect(storage.<T, RuntimeException>write(capture(work))).andAnswer(new
IAnswer<T>() {
+    return expect(storage.write(capture(work))).andAnswer(new IAnswer<T>() {
       @Override
       public T answer() {
         return work.getValue().apply(mutableStoreProvider);
@@ -124,9 +113,8 @@ public class StorageTestUtil {
     expect(mutableStoreProvider.getLockStore()).andReturn(lockStore).anyTimes();
     expect(mutableStoreProvider.getSchedulerStore()).andReturn(schedulerStore).anyTimes();
     expect(mutableStoreProvider.getJobUpdateStore()).andReturn(jobUpdateStore).anyTimes();
-    expectConsistentRead().anyTimes();
-    expectWeaklyConsistentRead().anyTimes();
-    expectWriteOperation().anyTimes();
+    expectRead().anyTimes();
+    expectWrite().anyTimes();
   }
 
   public IExpectationSetters<?> expectTaskFetch(

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/5116c220/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java b/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
index 2533d82..4c827b1 100644
--- a/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
@@ -217,7 +217,7 @@ public class JobUpdaterIT extends EasyMockTest {
 
   private String getTaskId(IJobKey job, int instanceId) {
     return Tasks.id(Iterables.getOnlyElement(
-        Storage.Util.consistentFetchTasks(
+        Storage.Util.fetchTasks(
             storage,
             Query.instanceScoped(job, instanceId).active())));
   }
@@ -271,7 +271,7 @@ public class JobUpdaterIT extends EasyMockTest {
       JobUpdateStatus expected,
       Multimap<Integer, JobUpdateAction> expectedActions) {
 
-    IJobUpdateDetails details = storage.consistentRead(new Work.Quiet<IJobUpdateDetails>()
{
+    IJobUpdateDetails details = storage.read(new Work.Quiet<IJobUpdateDetails>() {
       @Override
       public IJobUpdateDetails apply(StoreProvider storeProvider) {
         return storeProvider.getJobUpdateStore().fetchJobUpdateDetails(UPDATE_ID).get();
@@ -314,7 +314,7 @@ public class JobUpdaterIT extends EasyMockTest {
 
   private void assertJobState(IJobKey job, Map<Integer, ITaskConfig> expected) {
     Iterable<IScheduledTask> tasks =
-        Storage.Util.consistentFetchTasks(storage, Query.jobScoped(job).active());
+        Storage.Util.fetchTasks(storage, Query.jobScoped(job).active());
 
     Map<Integer, IScheduledTask> tasksByInstance =
         Maps.uniqueIndex(tasks, Tasks.SCHEDULED_TO_INSTANCE_ID);


Mime
View raw message