org.easymock.IExpectationSetters Java Examples

The following examples show how to use org.easymock.IExpectationSetters. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BatchWorkerUtil.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
public static <T> IExpectationSetters<CompletableFuture<T>> expectBatchExecute(
    BatchWorker<T> batchWorker,
    Storage storage,
    IMocksControl control,
    T resultValue) throws Exception {

  final CompletableFuture<T> result = new EasyMockTest.Clazz<CompletableFuture<T>>() { }
      .createMock(control);
  expect(result.get()).andReturn(resultValue).anyTimes();

  final Capture<Work<T>> capture = createCapture();
  return expect(batchWorker.execute(capture(capture))).andAnswer(() -> {
    storage.write((Storage.MutateWork.NoResult.Quiet) store -> capture.getValue().apply(store));
    return result;
  });
}
 
Example #2
Source File: QuotaManagerImplTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private IExpectationSetters<?> expectCronJobs(IJobConfiguration... jobs) {
  ImmutableSet.Builder<IJobConfiguration> builder = ImmutableSet.builder();
  for (IJobConfiguration job : jobs) {
    builder.add(job);
  }

  return expect(storageUtil.jobStore.fetchJobs()).andReturn(builder.build());
}
 
Example #3
Source File: MesosLogTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private IExpectationSetters<Position> expectWrite(String content) throws Exception {
  return expect(
      logWriter.append(EasyMock.aryEq(content.getBytes(StandardCharsets.UTF_8)),
          // Cast is needed to prevent NullPointerException on unboxing.
          EasyMock.eq((long) WRITE_TIMEOUT.getValue()),
          EasyMock.eq(WRITE_TIMEOUT.getUnit().getTimeUnit())));
}
 
Example #4
Source File: PreemptionVictimFilterTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private IExpectationSetters<Set<SchedulingFilter.Veto>> expectFiltering(
    final Optional<Veto> veto) {

  return expect(schedulingFilter.filter(
      EasyMock.anyObject(),
      EasyMock.anyObject()))
      .andAnswer(() -> veto.map(ImmutableSet::of).orElse(ImmutableSet.of()));
}
 
Example #5
Source File: MesosLogTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private IExpectationSetters<List<Log.Entry>> expectRead(Position position) throws Exception {
  expectSetPosition(position);
  return expect(logReader.read(
      position,
      position,
      READ_TIMEOUT.getValue(),
      READ_TIMEOUT.getUnit().getTimeUnit()));
}
 
Example #6
Source File: JobDiffTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private IExpectationSetters<?> expectFetch(IAssignedTask... results) {
  ImmutableSet.Builder<IScheduledTask> tasks = ImmutableSet.builder();
  for (IAssignedTask result : results) {
    tasks.add(IScheduledTask.build(new ScheduledTask().setAssignedTask(result.newBuilder())));
  }

  return expect(store.fetchTasks(Query.jobScoped(JOB).active()))
      .andReturn(tasks.build());
}
 
Example #7
Source File: TaskVarsTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private IExpectationSetters<?> expectGetHostAttributes(
    String host,
    String rackToReturn,
    ImmutableSet<String> dedicatedAttrs) {

  IHostAttributes attributes = IHostAttributes.build(new HostAttributes()
      .setHost(host)
      .setAttributes(ImmutableSet.of(
          new Attribute().setName("rack").setValues(ImmutableSet.of(rackToReturn)),
          new Attribute().setName("dedicated").setValues(dedicatedAttrs))));
  return expect(storageUtil.attributeStore.getHostAttributes(host))
      .andReturn(Optional.of(attributes));
}
 
Example #8
Source File: LogOpMatcher.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
/**
 * Sets an expectation for a snapshot.
 *
 * @param snapshot Expected snapshot.
 * @return An expectation setter.
 */
public IExpectationSetters<Position> expectSnapshot(DeduplicatedSnapshot snapshot) {
  try {
    LogEntry entry = Entries.deflate(LogEntry.deduplicatedSnapshot(snapshot));
    return expect(stream.append(sameEntry(entry)));
  } catch (CodingException e) {
    throw Throwables.propagate(e);
  }
}
 
Example #9
Source File: TaskSchedulerImplTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private IExpectationSetters<Set<String>> expectAssigned(
    IScheduledTask task,
    Map<String, TaskGroupKey> reservationMap) {

  return expect(assigner.maybeAssign(
      storageUtil.mutableStoreProvider,
      ResourceRequest.fromTask(
          task.getAssignedTask().getTask(),
          THERMOS_EXECUTOR,
          empty(),
          TIER_MANAGER),
      TaskGroupKey.from(task.getAssignedTask().getTask()),
      ImmutableSet.of(task.getAssignedTask()),
      reservationMap));
}
 
Example #10
Source File: SentryTestBase.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
protected SolrQueryRequest prepareCollAndUser(SolrCore core, SolrQueryRequest request,
    String collection, String user, boolean onlyOnce) throws Exception {
  CloudDescriptor mCloudDescriptor = EasyMock.createMock(CloudDescriptor.class);
  IExpectationSetters getCollNameExpect = EasyMock.expect(mCloudDescriptor.getCollectionName()).andReturn(collection);
  getCollNameExpect.anyTimes();
  IExpectationSetters getShardIdExpect = EasyMock.expect(mCloudDescriptor.getShardId()).andReturn("shard1");
  getShardIdExpect.anyTimes();
  EasyMock.replay(mCloudDescriptor);
  CoreDescriptor coreDescriptor = core.getCoreDescriptor();
  Field cloudDescField = CoreDescriptor.class.getDeclaredField("cloudDesc");
  cloudDescField.setAccessible(true);
  cloudDescField.set(coreDescriptor, mCloudDescriptor);

  HttpServletRequest httpServletRequest = EasyMock.createMock(HttpServletRequest.class);
  IExpectationSetters getAttributeUserExpect =
      EasyMock.expect(httpServletRequest.getAttribute(USER_NAME)).andReturn(user);
  if (!onlyOnce) {
    getAttributeUserExpect.anyTimes();
  }
  IExpectationSetters getAttributeDoAsUserExpect =
      EasyMock.expect(httpServletRequest.getAttribute(DO_AS_USER_NAME)).andReturn(null);
  if (!onlyOnce) {
    getAttributeDoAsUserExpect.anyTimes();
  }
  EasyMock.replay(httpServletRequest);
  request.getContext().put("httpRequest", httpServletRequest);
  return request;
}
 
Example #11
Source File: TestCrawlerSessionManagerValve.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private Request createRequestExpectations(String ip, HttpSession session, boolean isBot, String hostname,
        String contextPath, String userAgent) {
    Request request = EasyMock.createMock(Request.class);
    EasyMock.expect(request.getRemoteAddr()).andReturn(ip);
    EasyMock.expect(request.getHost()).andReturn(simpleHostWithName(hostname));
    EasyMock.expect(request.getContext()).andReturn(simpleContextWithName(contextPath));
    IExpectationSetters<HttpSession> setter = EasyMock.expect(request.getSession(false))
            .andReturn(null);
    if (isBot) {
        setter.andReturn(session);
    }
    EasyMock.expect(request.getHeaders("user-agent")).andReturn(Collections.enumeration(Arrays.asList(userAgent)));
    return request;
}
 
Example #12
Source File: TestDeviceServiceUpgradeDriver.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private IExpectationSetters<DeviceDriver> expectFindByProtocolAttributes() {
   AttributeMap protocolAttributes = AttributeMap.mapOf(
         DeviceService.DEVICE_ADV_PROTCOL_KEY.valueOf(device.getProtocol()),
         DeviceService.DEVICE_ADV_SUBPROTCOL_KEY.valueOf(device.getSubprotocol()),
         DeviceService.DEVICE_ADV_PROTOCOLID_KEY.valueOf(device.getProtocolid())
   );
   return
      EasyMock
         .expect(mockRegistry.findDriverFor("general", protocolAttributes, 0));
}
 
Example #13
Source File: SchedulerThriftInterfaceTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private IExpectationSetters<?> expectInstanceQuotaCheck(
    ITaskConfig config,
    QuotaCheckResult result) {

  return expect(quotaManager.checkInstanceAddition(
      config,
      1,
      storageUtil.mutableStoreProvider)).andReturn(result);
}
 
Example #14
Source File: SchedulerThriftInterfaceTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private IExpectationSetters<?> expectCronQuotaCheck(
    IJobConfiguration config,
    QuotaCheckResult result) {

  return expect(quotaManager.checkCronUpdate(config, storageUtil.mutableStoreProvider))
      .andReturn(result);
}
 
Example #15
Source File: BatchWorkerUtil.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
public static <T> IExpectationSetters<CompletableFuture<T>> expectBatchExecute(
    BatchWorker<T> batchWorker,
    Storage storage,
    IMocksControl control) throws Exception {

  return expectBatchExecute(batchWorker, storage, control, null);
}
 
Example #16
Source File: QuotaManagerImplTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private IExpectationSetters<?> expectNoJobUpdates() {
  return expect(jobUpdateStore.fetchJobUpdates(updateQuery(ROLE))).andReturn(ImmutableList.of());
}
 
Example #17
Source File: QuotaManagerImplTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private IExpectationSetters<?> expectNoCronJobs() {
  return expect(storageUtil.jobStore.fetchJobs()).andReturn(ImmutableSet.of());
}
 
Example #18
Source File: QuotaManagerImplTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private IExpectationSetters<?> expectNoTasks() {
  return expectTasks();
}
 
Example #19
Source File: QuotaManagerImplTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private IExpectationSetters<?> expectCronJob(IJobConfiguration job) {
  return expect(storageUtil.jobStore.fetchJob(job.getKey())).andReturn(Optional.of(job));
}
 
Example #20
Source File: SchedulerThriftInterfaceTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private IExpectationSetters<?> expectCronJob() {
  return expect(storageUtil.jobStore.fetchJob(JOB_KEY))
      .andReturn(Optional.of(IJobConfiguration.build(CRON_JOB)));
}
 
Example #21
Source File: QuotaManagerImplTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private IExpectationSetters<?> expectNoCronJob() {
  return expect(storageUtil.jobStore.fetchJob(anyObject(IJobKey.class)))
      .andReturn(Optional.empty());
}
 
Example #22
Source File: QuotaManagerImplTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private IExpectationSetters<Optional<IResourceAggregate>> expectQuota(IResourceAggregate quota) {
  return expect(storageUtil.quotaStore.fetchQuota(ROLE))
      .andReturn(Optional.of(quota));
}
 
Example #23
Source File: StorageTestUtil.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public <T> IExpectationSetters<T> expectRead() {
  Capture<Work<T, RuntimeException>> work = EasyMockTest.createCapture();
  return expect(storage.<T, RuntimeException>read(capture(work)))
      .andAnswer(() -> work.getValue().apply(storeProvider));
}
 
Example #24
Source File: StorageTestUtil.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public <T> IExpectationSetters<T> expectWrite() {
  Capture<MutateWork<T, RuntimeException>> work = EasyMockTest.createCapture();
  return expect(storage.<T, RuntimeException>write(capture(work)))
      .andAnswer(() -> work.getValue().apply(mutableStoreProvider));
}
 
Example #25
Source File: StorageTestUtil.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public IExpectationSetters<?> expectTaskFetch(
    Query.Builder query,
    ImmutableSet<IScheduledTask> result) {

  return expect(taskStore.fetchTasks(query)).andReturn(result);
}
 
Example #26
Source File: StorageTestUtil.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public IExpectationSetters<?> expectTaskFetch(String taskId, IScheduledTask result) {
  return expect(taskStore.fetchTask(taskId)).andReturn(Optional.of(result));
}
 
Example #27
Source File: StorageTestUtil.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public IExpectationSetters<?> expectTaskFetch(String taskId) {
  return expect(taskStore.fetchTask(taskId)).andReturn(Optional.empty());
}
 
Example #28
Source File: StorageTestUtil.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public IExpectationSetters<?> expectTaskFetch(Query.Builder query, IScheduledTask... result) {
  return expectTaskFetch(query, ImmutableSet.<IScheduledTask>builder().add(result).build());
}
 
Example #29
Source File: AttributeAggregateTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private IExpectationSetters<?> expectGetAttributes(String host, Attribute... attributes) {
  return expect(attributeStore.getHostAttributes(host)).andReturn(Optional.of(
      IHostAttributes.build(new HostAttributes()
          .setHost(host)
          .setAttributes(ImmutableSet.copyOf(attributes)))));
}
 
Example #30
Source File: GitRevisionHistoryTest.java    From MOE with Apache License 2.0 4 votes vote down vote up
private IExpectationSetters<String> expectLogCommand(
    GitClonedRepository mockRepo, String logFormat, String revName) throws CommandException {
  return expect(
      mockRepo.runGitCommand("log", "--max-count=1", "--format=" + logFormat, revName, "--"));
}