@Test public void testGetEmitter() { ComposingEmitterConfig config = EasyMock.createMock(ComposingEmitterConfig.class); EasyMock.expect(config.getEmitters()).andReturn(Collections.singletonList(testEmitterType)).anyTimes(); Injector injector = EasyMock.createMock(Injector.class); EasyMock.expect(injector.getInstance(Key.get(Emitter.class, Names.named(testEmitterType)))).andReturn(emitter); EasyMock.replay(config, injector); Emitter composingEmitter = new ComposingEmitterModule().getEmitter(config, injector); composingEmitter.start(); EasyMock.verify(config, emitter, injector); }
@Test(expected = IllegalStateException.class) public void testAddExceptionWhenClosed() { lookupReferencesManager.add("test", EasyMock.createMock(LookupExtractorFactoryContainer.class)); }
@Test public void testEmit() { Event e = EasyMock.createMock(Event.class); for (Emitter emitter : childEmitters) { emitter.emit(e); EasyMock.replay(emitter); } composingEmitter.emit(e); }
private static LoadQueuePeon createLoadingPeon(List<DataSegment> segments) { final Set<DataSegment> segs = ImmutableSet.copyOf(segments); final long loadingSize = segs.stream().mapToLong(DataSegment::getSize).sum(); final LoadQueuePeon mockPeon = EasyMock.createMock(LoadQueuePeon.class); EasyMock.expect(mockPeon.getSegmentsToLoad()).andReturn(segs).anyTimes(); EasyMock.expect(mockPeon.getSegmentsMarkedToDrop()).andReturn(new HashSet<>()).anyTimes(); EasyMock.expect(mockPeon.getLoadQueueSize()).andReturn(loadingSize).anyTimes(); EasyMock.expect(mockPeon.getNumberOfSegmentsInQueue()).andReturn(segs.size()).anyTimes(); return mockPeon; } }
@Before public void setUp() { resourceFactory = (ResourceFactory<String, String>) EasyMock.createMock(ResourceFactory.class); EasyMock.replay(resourceFactory); pool = new ResourcePool<String, String>( resourceFactory, new ResourcePoolConfig(2, TimeUnit.MINUTES.toMillis(4)) ); EasyMock.verify(resourceFactory); EasyMock.reset(resourceFactory); }
@Before public void setup() { emitter = EasyMock.createMock(Emitter.class); emitter.start(); EasyMock.replay(emitter); }
private Task createMockTask(String type) { Task mock = EasyMock.createMock(Task.class); EasyMock.expect(mock.getType()).andReturn(type).anyTimes(); EasyMock.replay(mock); return mock; }
@Before public void setUp() { tierSelectorStrategy = EasyMock.createMock(TierSelectorStrategy.class); expect(tierSelectorStrategy.getComparator()).andReturn(Integer::compare).anyTimes(); }
@Before public void setUp() { ServiceEmitter emitter = EasyMock.createMock(ServiceEmitter.class); EmittingLogger.registerEmitter(emitter); EasyMock.replay(emitter); }
/** * Tests whether the thread name is not modified if no naming pattern is * set. */ @Test public void testNewThreadNoNamingPattern() { final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class); final Runnable r = EasyMock.createMock(Runnable.class); final String name = "unchangedThreadName"; final Thread t = new Thread(name); EasyMock.expect(wrapped.newThread(r)).andReturn(t); EasyMock.replay(wrapped, r); final BasicThreadFactory factory = builder.wrappedFactory(wrapped).build(); assertSame("Wrong thread", t, factory.newThread(r)); assertEquals("Name was changed", name, t.getName()); EasyMock.verify(wrapped, r); }
private static ShardSpec shardSpec(String dimension, boolean contained) { ShardSpec shard = EasyMock.createMock(ShardSpec.class); EasyMock.expect(shard.getDomainDimensions()) .andReturn(ImmutableList.of(dimension)) .anyTimes(); EasyMock.expect(shard.possibleInDomain(EasyMock.anyObject())) .andReturn(contained) .anyTimes(); return shard; } }
/** * Tests whether the original priority is not changed if no priority is * specified. */ @Test public void testNewThreadNoPriority() { final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class); final Runnable r = EasyMock.createMock(Runnable.class); final int orgPriority = Thread.NORM_PRIORITY + 1; final Thread t = new Thread(); t.setPriority(orgPriority); EasyMock.expect(wrapped.newThread(r)).andReturn(t); EasyMock.replay(wrapped, r); final BasicThreadFactory factory = builder.wrappedFactory(wrapped).build(); assertSame("Wrong thread", t, factory.newThread(r)); assertEquals("Wrong priority", orgPriority, t.getPriority()); EasyMock.verify(wrapped, r); }
private static LoadQueuePeon createEmptyPeon() { final LoadQueuePeon mockPeon = EasyMock.createMock(LoadQueuePeon.class); EasyMock.expect(mockPeon.getSegmentsToLoad()).andReturn(new HashSet<>()).anyTimes(); EasyMock.expect(mockPeon.getSegmentsMarkedToDrop()).andReturn(new HashSet<>()).anyTimes(); EasyMock.expect(mockPeon.getLoadQueueSize()).andReturn(0L).anyTimes(); EasyMock.expect(mockPeon.getNumberOfSegmentsInQueue()).andReturn(0).anyTimes(); return mockPeon; }
@Test public void testRewriteURI() { DruidLeaderClient druidLeaderClient = EasyMock.createMock(DruidLeaderClient.class); EasyMock.expect(druidLeaderClient.findCurrentLeader()).andReturn("https://overlord:port"); HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class); EasyMock.expect(request.getQueryString()).andReturn("param1=test¶m2=test2").anyTimes(); // %3A is a colon; test to make sure urlencoded paths work right. EasyMock.expect(request.getRequestURI()).andReturn("/druid/over%3Alord/worker").anyTimes(); EasyMock.replay(druidLeaderClient, request); URI uri = URI.create(new OverlordProxyServlet(druidLeaderClient, null, null).rewriteTarget(request)); Assert.assertEquals("https://overlord:port/druid/over%3Alord/worker?param1=test¶m2=test2", uri.toString()); }
/** * Tests a successful initializeUnchecked() operation. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testInitializeUnchecked() throws ConcurrentException { @SuppressWarnings("unchecked") final ConcurrentInitializer<Object> init = EasyMock .createMock(ConcurrentInitializer.class); final Object result = new Object(); EasyMock.expect(init.get()).andReturn(result); EasyMock.replay(init); assertSame("Wrong result object", result, ConcurrentUtils .initializeUnchecked(init)); EasyMock.verify(init); }
/** * Tests a successful initialize() operation. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testInitialize() throws ConcurrentException { @SuppressWarnings("unchecked") final ConcurrentInitializer<Object> init = EasyMock .createMock(ConcurrentInitializer.class); final Object result = new Object(); EasyMock.expect(init.get()).andReturn(result); EasyMock.replay(init); assertSame("Wrong result object", result, ConcurrentUtils .initialize(init)); EasyMock.verify(init); }
/** * Tests multiple invocations of the shutdown() method. * * @throws java.lang.InterruptedException so we don't have to catch it */ @Test public void testShutdownMultipleTimes() throws InterruptedException { final ScheduledExecutorService service = EasyMock .createMock(ScheduledExecutorService.class); final ScheduledFuture<?> future = EasyMock.createMock(ScheduledFuture.class); prepareStartTimer(service, future); EasyMock.expect(Boolean.valueOf(future.cancel(false))).andReturn(Boolean.TRUE); EasyMock.replay(service, future); final TimedSemaphoreTestImpl semaphore = new TimedSemaphoreTestImpl(service, PERIOD, UNIT, LIMIT); semaphore.acquire(); for (int i = 0; i < 10; i++) { semaphore.shutdown(); } EasyMock.verify(service, future); }
/** * Tests whether the priority is set on newly created threads. */ @Test public void testNewThreadPriority() { final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class); final Runnable r = EasyMock.createMock(Runnable.class); final Thread t = new Thread(); EasyMock.expect(wrapped.newThread(r)).andReturn(t); EasyMock.replay(wrapped, r); final int priority = Thread.NORM_PRIORITY + 1; final BasicThreadFactory factory = builder.wrappedFactory(wrapped).priority( priority).build(); assertSame("Wrong thread", t, factory.newThread(r)); assertEquals("Wrong priority", priority, t.getPriority()); EasyMock.verify(wrapped, r); }
/** * Tests whether the original exception handler is not touched if none is * specified. */ @Test public void testNewThreadNoExHandler() { final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class); final Runnable r = EasyMock.createMock(Runnable.class); final Thread.UncaughtExceptionHandler handler = EasyMock .createMock(Thread.UncaughtExceptionHandler.class); final Thread t = new Thread(); t.setUncaughtExceptionHandler(handler); EasyMock.expect(wrapped.newThread(r)).andReturn(t); EasyMock.replay(wrapped, r, handler); final BasicThreadFactory factory = builder.wrappedFactory(wrapped).build(); assertSame("Wrong thread", t, factory.newThread(r)); assertEquals("Wrong exception handler", handler, t .getUncaughtExceptionHandler()); EasyMock.verify(wrapped, r, handler); } }
/** * Tests createIfAbsent() if a null map is passed in. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testCreateIfAbsentNullMap() throws ConcurrentException { @SuppressWarnings("unchecked") final ConcurrentInitializer<Integer> init = EasyMock .createMock(ConcurrentInitializer.class); EasyMock.replay(init); assertNull("Wrong result", ConcurrentUtils.createIfAbsent(null, "test", init)); EasyMock.verify(init); }