@Before
 public void setUp() {
   FakeClock clock = new FakeClock();
   clock.setNowMillis(NOW);
   storageUtil = new StorageTestUtil(this);
   snapshotStore = new SnapshotStoreImpl(clock, storageUtil.storage);
 }
 @Before
 public void setUp() {
   storage = MemStorage.newEmptyStorage();
   maintenance = createMock(MaintenanceController.class);
   stateManager = createMock(StateManager.class);
   assigner = createMock(TaskAssigner.class);
   retryStrategy = createMock(BackoffStrategy.class);
   driver = createMock(Driver.class);
   executor = createMock(ScheduledExecutorService.class);
   future = createMock(ScheduledFuture.class);
   returnDelay = createMock(OfferReturnDelay.class);
   clock = new FakeClock();
   clock.setNowMillis(0);
   flappingStrategy = createMock(BackoffStrategy.class);
   preemptor = createMock(Preemptor.class);
 }
Example #3
0
    @Override
    public TemporaryStorage apply(Snapshot snapshot) {
      final Storage storage = DbUtil.createFlaggedStorage();
      FakeClock clock = new FakeClock();
      clock.setNowMillis(snapshot.getTimestamp());
      final SnapshotStore<Snapshot> snapshotStore = new SnapshotStoreImpl(clock, storage);
      snapshotStore.applySnapshot(snapshot);

      return new TemporaryStorage() {
        @Override
        public void deleteTasks(final Query.Builder query) {
          storage.write(
              new MutateWork.NoResult.Quiet() {
                @Override
                public void execute(MutableStoreProvider storeProvider) {
                  Set<String> ids =
                      FluentIterable.from(storeProvider.getTaskStore().fetchTasks(query))
                          .transform(Tasks::id)
                          .toSet();
                  storeProvider.getUnsafeTaskStore().deleteTasks(ids);
                }
              });
        }

        @Override
        public Iterable<IScheduledTask> fetchTasks(final Query.Builder query) {
          return storage.read(
              new Work.Quiet<Iterable<IScheduledTask>>() {
                @Override
                public Iterable<IScheduledTask> apply(StoreProvider storeProvider) {
                  return storeProvider.getTaskStore().fetchTasks(query);
                }
              });
        }

        @Override
        public Snapshot toSnapshot() {
          return snapshotStore.createSnapshot();
        }
      };
    }