下面列出了com.google.common.collect.ImmutableSet#of ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void getPhysicalDevicesTest() throws IOException {
ImmutableSet<AppleDevice> physicalDevices;
try (OutputStream stdin = new ByteArrayOutputStream();
InputStream stdout = getClass().getResourceAsStream("testdata/idb-list.txt");
InputStream stderr = new ByteArrayInputStream(new byte[0])) {
FakeProcess fakeIdbList = new FakeProcess(0, stdin, stdout, stderr);
ProcessExecutorParams processExecutorParams =
ProcessExecutorParams.builder()
.setCommand(ImmutableList.of(IDB_PATH.toString(), "list-targets", "--json"))
.build();
FakeProcessExecutor fakeProcessExecutor =
new FakeProcessExecutor(ImmutableMap.of(processExecutorParams, fakeIdbList));
AppleDeviceController deviceController =
new AppleDeviceController(fakeProcessExecutor, IDB_PATH);
physicalDevices = deviceController.getPhysicalDevices();
}
ImmutableSet<ImmutableAppleDevice> expected =
ImmutableSet.of(
ImmutableAppleDevice.of("iPhone", "", "Booted", "device", "iOS 12.4", "arm64"));
assertEquals(physicalDevices, expected);
}
protected void testTreeConstructionWithResolve(
ImmutableMap<String, String> fileNameToGss,
String expectedOutput) {
parseAndBuildTree(fileNameToGss);
runPass();
ResolveCustomFunctionNodesForChunks<String> resolveFunctions =
new ResolveCustomFunctionNodesForChunks<String>(
tree.getMutatingVisitController(), errorManager,
ImmutableMap.of("someColorFunction", SOME_COLOR_FUNCTION),
false /* allowUnknownFunctions */,
ImmutableSet.<String>of() /* allowedNonStandardFunctions */,
new UniqueSuffixFunction());
resolveFunctions.runPass();
checkTreeDebugString(expectedOutput);
}
private FileSystem getCachingFileSystem(HdfsContext context, Path path)
throws IOException
{
HdfsConfigurationInitializer configurationInitializer = new HdfsConfigurationInitializer(config, ImmutableSet.of());
HiveHdfsConfiguration configuration = new HiveHdfsConfiguration(
configurationInitializer,
ImmutableSet.of(
rubixConfigInitializer,
(dynamicConfig, ignoredContext, ignoredUri) -> {
dynamicConfig.set("fs.file.impl", CachingLocalFileSystem.class.getName());
dynamicConfig.setBoolean("fs.gs.lazy.init.enable", true);
dynamicConfig.set("fs.azure.account.key", "Zm9vCg==");
dynamicConfig.set("fs.adl.oauth2.client.id", "test");
dynamicConfig.set("fs.adl.oauth2.refresh.url", "http://localhost");
dynamicConfig.set("fs.adl.oauth2.credential", "password");
}));
HdfsEnvironment environment = new HdfsEnvironment(configuration, config, new NoHdfsAuthentication());
return environment.getFileSystem(context, path);
}
@Test
@SuppressWarnings("PMD")
public void testTableOperations()
{
Set<SchemaTableName> aliceTables = ImmutableSet.of(new SchemaTableName("schema", "table"));
assertEquals(accessControlManager.filterTables(context(alice), aliceCatalog, aliceTables), aliceTables);
assertEquals(accessControlManager.filterTables(context(bob), "alice-catalog", aliceTables), ImmutableSet.of());
accessControlManager.checkCanCreateTable(context(alice), aliceTable);
accessControlManager.checkCanDropTable(context(alice), aliceTable);
accessControlManager.checkCanSelectFromColumns(context(alice), aliceTable, ImmutableSet.of());
accessControlManager.checkCanInsertIntoTable(context(alice), aliceTable);
accessControlManager.checkCanDeleteFromTable(context(alice), aliceTable);
accessControlManager.checkCanRenameColumn(context(alice), aliceTable);
try {
accessControlManager.checkCanCreateTable(context(bob), aliceTable);
} catch (AccessDeniedException expected) {
}
}
/**
* Test event requirements on a trace with no pre-defined events. They
* should all pass
*/
@Test
public void testNoPreDefinedEvents() {
/* A simple trace with no pre-defined events */
TmfTrace traceNoEvents = new TmfTraceStub();
TmfAbstractAnalysisRequirement req = new TmfAnalysisEventRequirement(ImmutableSet.of(EVENT1, EVENT3), PriorityLevel.MANDATORY);
assertTrue(req.test(traceNoEvents));
req = new TmfAnalysisEventRequirement(ImmutableSet.of(EVENT1, EVENT2), PriorityLevel.OPTIONAL);
assertTrue(req.test(traceNoEvents));
traceNoEvents.dispose();
}
@Test
public void allowsTheHostIfDefined() throws Exception {
given(req.getHeader("Origin")).willReturn("http://135.31.22.221");
CorsConfig allowedHosts = new CorsConfig(ImmutableSet.of("http://135.31.22.221"), "");
CorsFilter underTest = new CorsFilter(allowedHosts);
underTest.doFilter(req, res, chain);
verify(res, times(1)).setHeader("Access-Control-Allow-Origin", "http://135.31.22.221");
}
@Test
public void testCompilerFlagsDependency() throws IOException, InterruptedException {
ProjectWorkspace workspace =
TestDataHelper.createProjectWorkspaceForScenario(
this, "compiler_flag_macros", tmp.newFolder());
workspace.setUp();
String ocamlVersion = this.getOcamlVersion(workspace);
assumeTrue("Installed ocaml is too old for this test", "4.02.0".compareTo(ocamlVersion) <= 0);
BuildTarget binary = BuildTargetFactory.newInstance("//:main");
BuildTarget lib = BuildTargetFactory.newInstance("//:lib");
BuildTarget helper = BuildTargetFactory.newInstance("//:test");
ImmutableSet<BuildTarget> targets = ImmutableSet.of(binary, lib, helper);
// Build the binary.
workspace.runBuckCommand("build", binary.toString()).assertSuccess();
// Make sure the helper target is built as well.
BuckBuildLog buildLog = workspace.getBuildLog();
assertTrue(buildLog.getAllTargets().containsAll(targets));
buildLog.assertTargetBuiltLocally(binary);
// Make sure the ppx flag worked
String out = workspace.runBuckCommand("run", binary.toString()).getStdout();
assertEquals("42!\n", out);
}
@Override
public AnalysisEngineAction getAction() {
return new AnalysisEngineAction(
ImmutableSet.of(
Entity.class, Sentence.class, Paragraph.class, Temporal.class, Location.class),
ImmutableSet.of(Event.class));
}
@Override
public Set<RelOptRule> getRules(OptimizerRulesContext optimizerContext, PlannerPhase phase, SourceType pluginType) {
switch(phase) {
case LOGICAL:
return ImmutableSet.<RelOptRule>of(new SystemScanDrule(pluginType));
case PHYSICAL:
return ImmutableSet.of(SystemScanPrule.INSTANCE);
default:
return ImmutableSet.of();
}
}
@Test
public void testAddVertices() throws Exception {
Set<String> toBeAddedVertices = ImmutableSet.of("a", "b", "c");
DirectedGraph<String> directedGraph = new DirectedGraph<>();
Assert.assertTrue(directedGraph.addVertex("a"));
Assert.assertTrue(directedGraph.addVertex("b"));
Assert.assertTrue(directedGraph.addVertex("c"));
Assert.assertEquals(3, directedGraph.vertices().size());
Assert.assertTrue(toBeAddedVertices.containsAll(directedGraph.vertices()));
Assert.assertTrue(directedGraph.vertices().containsAll(toBeAddedVertices));
}
private Builder(@Nullable Supplier<String> processIdGenerator) {
// Default to Cisco IOS values
_adminCosts = computeDefaultAdminCosts(ConfigurationFormat.CISCO_IOS);
_areas = ImmutableMap.of();
_exportPolicySources = ImmutableSet.of();
_neighborConfigs = ImmutableMap.of();
_processIdGenerator = processIdGenerator;
// Default to Cisco IOS value
_summaryAdminCost =
RoutingProtocol.OSPF_IA.getSummaryAdministrativeCost(ConfigurationFormat.CISCO_IOS);
_generatedRoutes = ImmutableSet.of();
}
@Override
public ImmutableSet<? extends ComputeKey<? extends ComputeResult>> discoverPreliminaryDeps(
FileTreeKey key) {
return ImmutableSet.of(ImmutableDirectoryListKey.of(key.getPath()));
}
@Test
public void testCleanLocalShardsImmediately()
throws Exception
{
assertEquals(cleaner.getLocalShardsCleaned().getTotalCount(), 0);
TestingShardDao shardDao = dbi.onDemand(TestingShardDao.class);
MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
long tableId = metadataDao.insertTable("test", "test", false, false, null, 0);
UUID shard1 = randomUUID();
UUID shard2 = randomUUID();
UUID shard3 = randomUUID();
Set<UUID> shards = ImmutableSet.of(shard1, shard2, shard3);
for (UUID shard : shards) {
shardDao.insertShard(shard, tableId, null, 0, 0, 0, 0);
createShardFile(shard);
assertTrue(shardFileExists(shard));
}
int node1 = shardDao.insertNode("node1");
int node2 = shardDao.insertNode("node2");
// shard 1: referenced by this node
// shard 2: not referenced
// shard 3: referenced by other node
shardDao.insertShardNode(shard1, node1);
shardDao.insertShardNode(shard3, node2);
// clean shards immediately
Set<UUID> local = cleaner.getLocalShards();
cleaner.cleanLocalShardsImmediately(local);
assertEquals(cleaner.getLocalShardsCleaned().getTotalCount(), 2);
// shards 2 and 3 should be deleted
// shard 1 is referenced by this node
assertTrue(shardFileExists(shard1));
assertFalse(shardFileExists(shard2));
assertFalse(shardFileExists(shard3));
}
@Override
public Set<Stream> getResultStreams() {
return ImmutableSet.of(this.resultStream);
}
@Test
public void testSerializationRoundtrip()
throws Exception
{
Symbol windowSymbol = symbolAllocator.newSymbol("sum", BIGINT);
ResolvedFunction resolvedFunction = metadata.resolveFunction(QualifiedName.of("sum"), fromTypes(BIGINT));
WindowNode.Frame frame = new WindowNode.Frame(
WindowFrame.Type.RANGE,
FrameBound.Type.UNBOUNDED_PRECEDING,
Optional.empty(),
FrameBound.Type.UNBOUNDED_FOLLOWING,
Optional.empty(),
Optional.empty(),
Optional.empty());
PlanNodeId id = newId();
WindowNode.Specification specification = new WindowNode.Specification(
ImmutableList.of(columnA),
Optional.of(new OrderingScheme(
ImmutableList.of(columnB),
ImmutableMap.of(columnB, SortOrder.ASC_NULLS_FIRST))));
Map<Symbol, WindowNode.Function> functions = ImmutableMap.of(windowSymbol, new WindowNode.Function(resolvedFunction, ImmutableList.of(columnC.toSymbolReference()), frame, false));
Optional<Symbol> hashSymbol = Optional.of(columnB);
Set<Symbol> prePartitionedInputs = ImmutableSet.of(columnA);
WindowNode windowNode = new WindowNode(
id,
sourceNode,
specification,
functions,
hashSymbol,
prePartitionedInputs,
0);
String json = objectMapper.writeValueAsString(windowNode);
WindowNode actualNode = objectMapper.readValue(json, WindowNode.class);
assertEquals(actualNode.getId(), windowNode.getId());
assertEquals(actualNode.getSpecification(), windowNode.getSpecification());
assertEquals(actualNode.getWindowFunctions(), windowNode.getWindowFunctions());
assertEquals(actualNode.getFrames(), windowNode.getFrames());
assertEquals(actualNode.getHashSymbol(), windowNode.getHashSymbol());
assertEquals(actualNode.getPrePartitionedInputs(), windowNode.getPrePartitionedInputs());
assertEquals(actualNode.getPreSortedOrderPrefix(), windowNode.getPreSortedOrderPrefix());
}
@Override
public Set<Integer> getValidArgsSizes() {
return ImmutableSet.of(1);
}
@Test
public void testView() {
ImmutableSet<Item> list = ImmutableSet.of(oneItem);
assertEquals(list, stateInit.view());
}
@Override
public Set<Location> resolve(SpecifierContext ctxt) {
return ImmutableSet.of();
}
@Override
public Set<Integer> codes() {
return ImmutableSet.of(CommandCode.REQ_TYPE_CPU_THREAD_NUM.getCode());
}
@Override
public Iterable<String> getClientEnvironmentVariables() {
return ImmutableSet.of();
}