@Test public void testGetThriftDeserializer() { Properties schema = new Properties(); schema.setProperty(SERIALIZATION_LIB, ThriftDeserializer.class.getName()); schema.setProperty(SERIALIZATION_CLASS, IntString.class.getName()); schema.setProperty(SERIALIZATION_FORMAT, TBinaryProtocol.class.getName()); assertInstanceOf(getDeserializer(new Configuration(false), schema), ThriftDeserializer.class); }
protected void assertExpectedTableLayoutHandle(ConnectorTableLayoutHandle actualTableLayoutHandle, ConnectorTableLayoutHandle expectedTableLayoutHandle) { assertInstanceOf(actualTableLayoutHandle, HiveTableLayoutHandle.class); assertInstanceOf(expectedTableLayoutHandle, HiveTableLayoutHandle.class); HiveTableLayoutHandle actual = (HiveTableLayoutHandle) actualTableLayoutHandle; HiveTableLayoutHandle expected = (HiveTableLayoutHandle) expectedTableLayoutHandle; assertExpectedPartitions(actual.getPartitions().get(), expected.getPartitions().get()); }
@Test public void testCustomCredentialsProvider() throws Exception { Configuration config = new Configuration(); config.set(S3_USE_INSTANCE_CREDENTIALS, "false"); config.set(S3_CREDENTIALS_PROVIDER, TestCredentialsProvider.class.getName()); try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) { fs.initialize(new URI("s3n://test-bucket/"), config); assertInstanceOf(getAwsCredentialsProvider(fs), TestCredentialsProvider.class); } }
@Test public void testEncryptionMaterialsProvider() throws Exception { Configuration config = new Configuration(); config.set(S3_ENCRYPTION_MATERIALS_PROVIDER, TestEncryptionMaterialsProvider.class.getName()); try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) { fs.initialize(new URI("s3n://test-bucket/"), config); assertInstanceOf(fs.getS3Client(), AmazonS3EncryptionClient.class); } }
@Test public void testGetConnectorFactory() { AtopPlugin plugin = new AtopPlugin(); assertInstanceOf(getOnlyElement(plugin.getConnectorFactories()), AtopConnectorFactory.class); } }
@Test public void testPlugin() { ThriftPlugin plugin = loadPlugin(ThriftPlugin.class); ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories()); assertInstanceOf(factory, ThriftConnectorFactory.class); Map<String, String> config = ImmutableMap.of("presto.thrift.client.addresses", "localhost:7779"); Connector connector = factory.create("test", config, new TestingConnectorContext()); assertNotNull(connector); assertInstanceOf(connector, ThriftConnector.class); }
@Test public void testKMSEncryptionMaterialsProvider() throws Exception { Configuration config = new Configuration(); config.set(S3_KMS_KEY_ID, "test-key-id"); try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) { fs.initialize(new URI("s3n://test-bucket/"), config); assertInstanceOf(fs.getS3Client(), AmazonS3EncryptionClient.class); } }
@Test public void testFailsValidation() { ConstrainedPowerOfTwo object = new ConstrainedPowerOfTwo(11); Set<ConstraintViolation<ConstrainedPowerOfTwo>> violations = VALIDATOR.validate(object); assertEquals(violations.size(), 2); for (ConstraintViolation<ConstrainedPowerOfTwo> violation : violations) { assertInstanceOf(violation.getConstraintDescriptor().getAnnotation(), PowerOfTwo.class); } }
@Test public void testStaticCredentials() throws Exception { Configuration config = new Configuration(); config.set(S3_ACCESS_KEY, "test_secret_access_key"); config.set(S3_SECRET_KEY, "test_access_key_id"); // the static credentials should be preferred try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) { fs.initialize(new URI("s3n://test-bucket/"), config); assertInstanceOf(getAwsCredentialsProvider(fs), AWSStaticCredentialsProvider.class); } }
@Test public void testInstanceCredentialsEnabled() throws Exception { Configuration config = new Configuration(); // instance credentials are enabled by default try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) { fs.initialize(new URI("s3n://test-bucket/"), config); assertInstanceOf(getAwsCredentialsProvider(fs), InstanceProfileCredentialsProvider.class); } }
@Test public void testCompatibleStaticCredentials() throws Exception { Configuration config = new Configuration(); config.set(S3_ACCESS_KEY, "test_secret_access_key"); config.set(S3_SECRET_KEY, "test_access_key_id"); config.set(S3_ENDPOINT, "test.example.endpoint.com"); config.set(S3_SIGNER_TYPE, "S3SignerType"); // the static credentials should be preferred try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) { fs.initialize(new URI("s3a://test-bucket/"), config); assertInstanceOf(getAwsCredentialsProvider(fs), AWSStaticCredentialsProvider.class); } }
@BeforeClass public void setup() throws Exception { server = new TestingPrestoServer(ImmutableList.of(new TestGenerateTokenFilterModule())); httpClient = (JettyHttpClient) server.getInstance(Key.get(HttpClient.class, GenerateTokenFilterTest.class)); // extract the filter List<HttpRequestFilter> filters = httpClient.getRequestFilters(); assertEquals(filters.size(), 2); assertInstanceOf(filters.get(1), GenerateTraceTokenRequestFilter.class); filter = (GenerateTraceTokenRequestFilter) filters.get(1); }
@Test public void testStartup() { RedisPlugin plugin = new RedisPlugin(); ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories()); assertInstanceOf(factory, RedisConnectorFactory.class); Connector c = factory.create( "test-connector", ImmutableMap.<String, String>builder() .put("redis.table-names", "test") .put("redis.nodes", "localhost:6379") .build(), new TestingConnectorContext()); assertNotNull(c); } }
@Test public void testSpinup() { KafkaPlugin plugin = new KafkaPlugin(); ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories()); assertInstanceOf(factory, KafkaConnectorFactory.class); Connector c = factory.create( "test-connector", ImmutableMap.<String, String>builder() .put("kafka.table-names", "test") .put("kafka.nodes", "localhost:9092") .build(), new TestingConnectorContext()); assertNotNull(c); } }
private static void assertCreateConnector(String metastoreUri) { HiveConnectorFactory connectorFactory = new HiveConnectorFactory( "hive-test", HiveConnector.class.getClassLoader(), Optional.empty()); Map<String, String> config = ImmutableMap.<String, String>builder() .put("hive.metastore.uri", metastoreUri) .build(); Connector connector = connectorFactory.create("hive-test", config, new TestingConnectorContext()); ConnectorTransactionHandle transaction = connector.beginTransaction(READ_UNCOMMITTED, true); assertInstanceOf(connector.getMetadata(transaction), ClassLoaderSafeConnectorMetadata.class); assertInstanceOf(connector.getSplitManager(), ClassLoaderSafeConnectorSplitManager.class); assertInstanceOf(connector.getPageSourceProvider(), ConnectorPageSourceProvider.class); connector.commit(transaction); }
protected void assertExpectedPartitions(List<HivePartition> actualPartitions, Iterable<HivePartition> expectedPartitions) { Map<String, ?> actualById = uniqueIndex(actualPartitions, HivePartition::getPartitionId); for (Object expected : expectedPartitions) { assertInstanceOf(expected, HivePartition.class); HivePartition expectedPartition = (HivePartition) expected; Object actual = actualById.get(expectedPartition.getPartitionId()); assertEquals(actual, expected); assertInstanceOf(actual, HivePartition.class); HivePartition actualPartition = (HivePartition) actual; assertNotNull(actualPartition, "partition " + expectedPartition.getPartitionId()); assertEquals(actualPartition.getPartitionId(), expectedPartition.getPartitionId()); assertEquals(actualPartition.getKeys(), expectedPartition.getKeys()); assertEquals(actualPartition.getTableName(), expectedPartition.getTableName()); } }
protected static void assertPageSourceType(ConnectorPageSource pageSource, HiveStorageFormat hiveStorageFormat) { if (pageSource instanceof RecordPageSource) { RecordCursor hiveRecordCursor = ((RecordPageSource) pageSource).getCursor(); hiveRecordCursor = ((HiveRecordCursor) hiveRecordCursor).getRegularColumnRecordCursor(); if (hiveRecordCursor instanceof HiveCoercionRecordCursor) { hiveRecordCursor = ((HiveCoercionRecordCursor) hiveRecordCursor).getRegularColumnRecordCursor(); } assertInstanceOf(hiveRecordCursor, recordCursorType(hiveStorageFormat), hiveStorageFormat.name()); } else { assertInstanceOf(((HivePageSource) pageSource).getPageSource(), pageSourceType(hiveStorageFormat), hiveStorageFormat.name()); } }
private static void testProjectRange(Block block, Class<? extends Block> expectedResultType, DictionaryAwarePageProjection projection, boolean forceYield) { DriverYieldSignal yieldSignal = new DriverYieldSignal(); Work<Block> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsRange(5, 10)); Block result; if (forceYield) { result = projectWithYield(work, yieldSignal); } else { assertTrue(work.process()); result = work.getResult(); } assertBlockEquals( BIGINT, result, block.getRegion(5, 10)); assertInstanceOf(result, expectedResultType); }
private static void testProjectList(Block block, Class<? extends Block> expectedResultType, DictionaryAwarePageProjection projection, boolean forceYield) { DriverYieldSignal yieldSignal = new DriverYieldSignal(); int[] positions = {0, 2, 4, 6, 8, 10}; Work<Block> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsList(positions, 0, positions.length)); Block result; if (forceYield) { result = projectWithYield(work, yieldSignal); } else { assertTrue(work.process()); result = work.getResult(); } assertBlockEquals( BIGINT, result, block.copyPositions(positions, 0, positions.length)); assertInstanceOf(result, expectedResultType); }
private static void testProjectFastReturnIgnoreYield(Block block, DictionaryAwarePageProjection projection) { DriverYieldSignal yieldSignal = new DriverYieldSignal(); Work<Block> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsRange(5, 10)); yieldSignal.setWithDelay(1, executor); yieldSignal.forceYieldForTesting(); // yield signal is ignored given the block has already been loaded assertTrue(work.process()); Block result = work.getResult(); yieldSignal.reset(); assertBlockEquals( BIGINT, result, block.getRegion(5, 10)); assertInstanceOf(result, DictionaryBlock.class); }