本文整理汇总了Java中com.google.common.base.Suppliers.ofInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Suppliers.ofInstance方法的具体用法?Java Suppliers.ofInstance怎么用?Java Suppliers.ofInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.base.Suppliers
的用法示例。
在下文中一共展示了Suppliers.ofInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRenaming_exceptionalReturn
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@GwtIncompatible // threads
public void testRenaming_exceptionalReturn() throws Exception {
String oldName = Thread.currentThread().getName();
final Supplier<String> newName = Suppliers.ofInstance("MyCrazyThreadName");
class MyException extends Exception {}
Callable<Void> callable = new Callable<Void>() {
@Override public Void call() throws Exception {
assertEquals(Thread.currentThread().getName(), newName.get());
throw new MyException();
}
};
try {
Callables.threadRenaming(callable, newName).call();
fail();
} catch (MyException expected) {}
assertEquals(oldName, Thread.currentThread().getName());
}
示例2: testRenaming_noPermissions
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@GwtIncompatible // threads
public void testRenaming_noPermissions() throws Exception {
System.setSecurityManager(new SecurityManager() {
@Override public void checkAccess(Thread t) {
throw new SecurityException();
}
@Override public void checkPermission(Permission perm) {
// Do nothing so we can clear the security manager at the end
}
});
try {
final String oldName = Thread.currentThread().getName();
Supplier<String> newName = Suppliers.ofInstance("MyCrazyThreadName");
Callable<Void> callable = new Callable<Void>() {
@Override public Void call() throws Exception {
assertEquals(Thread.currentThread().getName(), oldName);
return null;
}
};
Callables.threadRenaming(callable, newName).call();
assertEquals(oldName, Thread.currentThread().getName());
} finally {
System.setSecurityManager(null);
}
}
示例3: EnrichmentExample
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
public EnrichmentExample(StorageFactory storageFactory) {
this.storageFactory = storageFactory;
final UserNameLookup userNameLookup = new UserNameLookup();
final EventEnricher enricher = EventEnricher
.newBuilder()
.addFieldEnrichment(UserId.class, PersonName.class, userNameLookup)
.build();
final Supplier<StorageFactory> storageFactorySupplier = Suppliers.ofInstance(storageFactory);
final EventBus eventBus = EventBus.newBuilder()
.setStorageFactory(storageFactorySupplier.get())
.setEnricher(enricher)
.build();
eventBus.subscribe(userNameLookup);
eventBus.subscribe(new Printer());
this.boundedContext = BoundedContext.newBuilder()
.setEventBus(eventBus)
.setStorageFactorySupplier(storageFactorySupplier)
.build();
}
示例4: testPollSkipsEmptyChannels
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Test
public void testPollSkipsEmptyChannels() {
EventReaderDAO readerDao = mock(EventReaderDAO.class);
EventStore eventStore = new DefaultEventStore(readerDao, mock(EventWriterDAO.class), new AstyanaxEventIdSerializer(), new MockClaimStore());
DedupQueue q = new DedupQueue("test-queue", "read", "write",
mock(QueueDAO.class), eventStore, Suppliers.ofInstance(true), mock(ScheduledExecutorService.class), getPersistentSortedQueueFactory(),
mock(MetricRegistry.class));
q.startAndWait();
// The first poll checks the read channel, find it empty, checks the write channel.
q.poll(Duration.standardSeconds(30), new SimpleEventSink(10));
verify(readerDao).readNewer(eq("read"), Matchers.<EventSink>any());
verify(readerDao).readNewer(eq("write"), Matchers.<EventSink>any());
verifyNoMoreInteractions(readerDao);
reset(readerDao);
// Subsequent polls w/in a short window skips the poll operations.
q.poll(Duration.standardSeconds(30), new SimpleEventSink(10));
verifyNoMoreInteractions(readerDao);
}
示例5: testPeekChecksAllChannels
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Test
public void testPeekChecksAllChannels() {
EventReaderDAO readerDao = mock(EventReaderDAO.class);
EventStore eventStore = new DefaultEventStore(readerDao, mock(EventWriterDAO.class), new AstyanaxEventIdSerializer(), new MockClaimStore());
DedupQueue q = new DedupQueue("test-queue", "read", "write",
mock(QueueDAO.class), eventStore, Suppliers.ofInstance(true), mock(ScheduledExecutorService.class), getPersistentSortedQueueFactory(),
mock(MetricRegistry.class));
q.startAndWait();
// The first peek checks the read channel, find it empty, checks the write channel.
q.peek(new SimpleEventSink(10));
verify(readerDao).readAll(eq("read"), Matchers.<EventSink>any(), (Date) Matchers.isNull());
verify(readerDao).readNewer(eq("write"), Matchers.<EventSink>any());
verifyNoMoreInteractions(readerDao);
reset(readerDao);
// Subsequent peeks w/in a short window still peek the read channel, skip polling the write channel.
q.peek(new SimpleEventSink(10));
verify(readerDao).readAll(eq("read"), Matchers.<EventSink>any(), (Date) Matchers.isNull());
verifyNoMoreInteractions(readerDao);
}
示例6: testRenaming
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@GwtIncompatible // threads
public void testRenaming() throws Exception {
String oldName = Thread.currentThread().getName();
final Supplier<String> newName = Suppliers.ofInstance("MyCrazyThreadName");
Callable<Void> callable = new Callable<Void>() {
@Override public Void call() throws Exception {
assertEquals(Thread.currentThread().getName(), newName.get());
return null;
}
};
Callables.threadRenaming(callable, newName).call();
assertEquals(oldName, Thread.currentThread().getName());
}
示例7: setup
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Before
public void setup() {
Supplier<GeneralOptions> generalOptionsSupplier = Suppliers.ofInstance(new GeneralOptions(
FileSystems.getDefault(), /*verbose=*/true,
LogConsole.writeOnlyConsole(System.out, /*verbose=*/true)));
options = new GerritOptions(generalOptionsSupplier, new GitOptions(generalOptionsSupplier));
jcommander = new JCommander(ImmutableList.of(options));
}
示例8: testFromBean
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Test
public void testFromBean() throws Exception {
Example e = new Example() {
@Override
public Supplier<String> getHost() {
return Suppliers.ofInstance("hello");
}
@Override
public int getPort() {
return 90;
}
@Override
public String getUser() {
return "admin";
}
@Override
public boolean isAuto() {
return true;
}
@Override
public Optional<String> alias() {
return Optional.of("demo");
}
};
Config c = ConfigFactory.fromBean(Example.class, e);
assertEquals("hello", c.getString("host").get());
assertEquals(90, c.getInteger("port").get().intValue());
assertEquals(true, c.getBoolean("auto").get().booleanValue());
assertEquals("demo", c.getString("alias").get());
}
示例9: getRegions
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
private final Supplier<Set<String>> getRegions() {
Set<String> regions = ImmutableSet.<String>builder()
.add("oss-cn-hangzhou")
.add("oss-cn-qingdao")
.add("oss-cn-beijing")
.add("oss-cn-hongkong")
.add("oss-cn-shenzhen")
.add("oss-cn-shanghai")
.add("oss-us-west-1")
.add("oss-ap-southeast-1")
.build();
return Suppliers.ofInstance(regions);
}
示例10: MinLagDurationTask
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Inject
public MinLagDurationTask(TaskRegistry taskRegistry,
@Maintenance String scope,
@GlobalFullConsistencyZooKeeper CuratorFramework curator,
@MinLagDurationValues Map<String, ValueStore<Duration>> durationCache) {
super(taskRegistry, scope + "-compaction-lag", "Full consistency minimum lag",
durationCache, curator, new ZkDurationSerializer(),
Suppliers.ofInstance(MinLagConsistencyTimeProvider.DEFAULT_LAG));
}
示例11: accessFromContainerToOSS
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Provides
@Singleton
protected final Supplier<Map<ContainerAccess, CannedAccessControlList>> accessFromContainerToOSS() {
Map<ContainerAccess, CannedAccessControlList> regions = ImmutableMap
.<ContainerAccess, CannedAccessControlList>builder()
.put(ContainerAccess.PRIVATE, CannedAccessControlList.Private)
.put(ContainerAccess.PUBLIC_READ, CannedAccessControlList.PublicRead)
.build();
return Suppliers.ofInstance(regions);
}
示例12: getGroupByQueryRunnerFactory
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
private static GroupByQueryRunnerFactory getGroupByQueryRunnerFactory() {
ObjectMapper mapper = new DefaultObjectMapper();
GroupByQueryConfig config = new GroupByQueryConfig();
config.setMaxIntermediateRows(10000);
Supplier<GroupByQueryConfig> configSupplier = Suppliers.ofInstance(config);
GroupByQueryEngine engine = new GroupByQueryEngine(configSupplier, Utils.getBufferPool());
GroupByQueryRunnerFactory factory =
new GroupByQueryRunnerFactory(engine, Utils.NOOP_QUERYWATCHER, configSupplier,
new GroupByQueryQueryToolChest(configSupplier, mapper, engine, Utils.getBufferPool(),
Utils.NoopIntervalChunkingQueryRunnerDecorator()), Utils.getBufferPool());
return factory;
}
示例13: testDiscardedUpdatesOverMultipleEventStorePolls
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Test
public void testDiscardedUpdatesOverMultipleEventStorePolls() {
final List<String> actualIds = Lists.newArrayList();
DedupEventStore dedupEventStore = mock(DedupEventStore.class);
DatabusEventStore eventStore = new DatabusEventStore(mock(EventStore.class), dedupEventStore, Suppliers.ofInstance(true)) {
int iteration = 0;
@Override
public boolean poll(String subscription, Duration claimTtl, EventSink sink) {
// The first 10 polls will supply a single redundant update each, then the 11th poll will return
// an empty queue return value
if (iteration++ < 10) {
String id = "a" + iteration;
actualIds.add(id);
assertTrue(sink.remaining() > 0);
EventSink.Status status = sink.accept(newEvent(id, "table", "key", TimeUUIDs.newUUID()));
assertEquals(status, EventSink.Status.ACCEPTED_CONTINUE);
return true;
}
return false;
}
};
Map<String, Object> content = entity("table", "key", ImmutableMap.of("rating", "5"));
// Create a custom annotated content which returns all changes as redundant
DataProvider.AnnotatedContent annotatedContent = mock(DataProvider.AnnotatedContent.class);
when(annotatedContent.getContent()).thenReturn(content);
when(annotatedContent.isChangeDeltaRedundant(any(UUID.class))).thenReturn(true);
OwnerAwareDatabus databus = newDatabus(eventStore, new TestDataProvider().add(annotatedContent));
PollResult result = databus.poll("id", "test-subscription", Duration.standardSeconds(30), 1);
assertFalse(result.getEventIterator().hasNext());
assertFalse(result.hasMoreEvents());
// Since each event came from a separate batch from the underlying event store they should each be deleted
// in separate calls.
for (String actualId : actualIds) {
verify(dedupEventStore).delete("test-subscription", ImmutableList.of(actualId), true);
}
verifyNoMoreInteractions(dedupEventStore);
}
示例14: newDatabus
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
private DefaultDatabus newDatabus(DatabusEventStore eventStore, DataProvider dataProvider, Clock clock) {
LifeCycleRegistry lifeCycle = mock(LifeCycleRegistry.class);
EventBus eventBus = mock(EventBus.class);
SubscriptionDAO subscriptionDao = mock(SubscriptionDAO.class);
SubscriptionEvaluator subscriptionEvaluator = mock(SubscriptionEvaluator.class);
JobService jobService = mock(JobService.class);
JobHandlerRegistry jobHandlerRegistry = mock(JobHandlerRegistry.class);
DatabusAuthorizer databusAuthorizer = ConstantDatabusAuthorizer.ALLOW_ALL;
return new DefaultDatabus(lifeCycle, eventBus, dataProvider, subscriptionDao, eventStore, subscriptionEvaluator,
jobService, jobHandlerRegistry, databusAuthorizer, "replication",
Suppliers.ofInstance(Conditions.alwaysFalse()), mock(ExecutorService.class), new MetricRegistry(), clock);
}
示例15: testUncheckedByDefaultModuleDependencies
import com.google.common.base.Suppliers; //导入方法依赖的package包/类
public void testUncheckedByDefaultModuleDependencies() {
ModuleToImport existing = new ModuleToImport(EXISTING_MODULE, myModule2.location,
Suppliers.ofInstance(ImmutableSet.of(myModule1.name)));
setModules(myModule1, existing);
assertEquals(OK, myModel.getModuleState(myModule1));
myModel.setSelected(existing, true);
assertEquals(REQUIRED, myModel.getModuleState(myModule1));
}