io.airlift.testing.Assertions类的使用及代码示例

x33g5p2x  于11个月前 转载在 其他  
字(14.8k)|赞(0)|评价(0)|浏览(30)

本文整理了Java中io.airlift.testing.Assertions类的一些代码示例,展示了Assertions类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assertions类的具体详情如下:
包路径:io.airlift.testing.Assertions
类名称:Assertions

Assertions介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

@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);
  }
}

代码示例来源:origin: prestodb/presto

@Test
public void testBuildSqlWithVarchar()
    throws SQLException
{
  TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(
      columns.get(3), Domain.create(SortedRangeSet.copyOf(VARCHAR,
          ImmutableList.of(
              Range.range(VARCHAR, utf8Slice("test_str_700"), true, utf8Slice("test_str_702"), false),
              Range.equal(VARCHAR, utf8Slice("test_str_180")),
              Range.equal(VARCHAR, utf8Slice("test_str_196")))),
          false)));
  Connection connection = database.getConnection();
  try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain, Optional.empty());
      ResultSet resultSet = preparedStatement.executeQuery()) {
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    while (resultSet.next()) {
      builder.add((String) resultSet.getObject("col_3"));
    }
    assertEquals(builder.build(), ImmutableSet.of("test_str_700", "test_str_701", "test_str_180", "test_str_196"));
    assertContains(preparedStatement.toString(), "\"col_3\" >= ?");
    assertContains(preparedStatement.toString(), "\"col_3\" < ?");
    assertContains(preparedStatement.toString(), "\"col_3\" IN (?,?)");
  }
}

代码示例来源:origin: prestodb/presto

@Test
public void testReserved()
{
  for (StandardErrorCode errorCode : StandardErrorCode.values()) {
    assertLessThan(code(errorCode), EXTERNAL_ERROR_START);
  }
}

代码示例来源:origin: io.airlift/configuration

@Test
public void testDefaultsFailNotDefault()
{
  boolean pass = true;
  try {
    Map<String, Object> expectedAttributeValues = new HashMap<>();
    expectedAttributeValues.put("Name", "Dain");
    expectedAttributeValues.put("Email", "dain@proofpoint.com");
    expectedAttributeValues.put("Phone", "42");
    expectedAttributeValues.put("HomePage", URI.create("http://iq80.com"));
    ConfigAssertions.assertDefaults(expectedAttributeValues, PersonConfig.class);
  }
  catch (AssertionError e) {
    // expected
    pass = false;
    assertContains(e.getMessage(), "Phone");
  }
  if (pass) {
    fail("Expected AssertionError");
  }
}

代码示例来源:origin: io.airlift.discovery/discovery-server

@Test
public void testPutNew()
{
  DynamicAnnouncement announcement = new DynamicAnnouncement("testing", "alpha", "/a/b/c", ImmutableSet.of(
      new DynamicServiceAnnouncement(Id.<Service>random(), "storage", ImmutableMap.of("http", "http://localhost:1111")))
  );
  Id<Node> nodeId = Id.random();
  Response response = resource.put(nodeId, new MockUriInfo(URI.create("http://localhost:8080/v1/announcement/" + nodeId.toString())), announcement);
  assertNotNull(response);
  assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode());
  assertEqualsIgnoreOrder(store.getAll(), transform(announcement.getServiceAnnouncements(), toServiceWith(nodeId, announcement.getLocation(), announcement.getPool())));
}

代码示例来源:origin: prestodb/presto

@SuppressWarnings({"OverlyStrongTypeCast", "ConstantConditions"})
@Test
public void testGetMetadataRetryCounter()
{
  int maxRetries = 2;
  try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) {
    MockAmazonS3 s3 = new MockAmazonS3();
    s3.setGetObjectMetadataHttpCode(SC_INTERNAL_SERVER_ERROR);
    Configuration configuration = new Configuration();
    configuration.set(S3_MAX_BACKOFF_TIME, "1ms");
    configuration.set(S3_MAX_RETRY_TIME, "5s");
    configuration.setInt(S3_MAX_CLIENT_RETRIES, maxRetries);
    fs.initialize(new URI("s3n://test-bucket/"), configuration);
    fs.setS3Client(s3);
    fs.getS3ObjectMetadata(new Path("s3n://test-bucket/test"));
  }
  catch (Throwable expected) {
    assertInstanceOf(expected, AmazonS3Exception.class);
    assertEquals(((AmazonS3Exception) expected).getStatusCode(), SC_INTERNAL_SERVER_ERROR);
    assertEquals(PrestoS3FileSystem.getFileSystemStats().getGetMetadataRetries().getTotalCount(), maxRetries);
  }
}

代码示例来源:origin: prestodb/presto

@Test
public void testViews()
  metadata.createSchema(SESSION, "test", ImmutableMap.of());
  assertEqualsIgnoreOrder(list, ImmutableList.of(test1, test2));
  assertEquals(views.keySet(), ImmutableSet.of(test1, test2));
  assertEquals(views.get(test1).getViewData(), "test1");
  assertEquals(views.get(test2).getViewData(), "test2");

代码示例来源:origin: prestodb/presto

@Test
public void test()
    throws SQLException
      try (ResultSet rs = statement.executeQuery("bogus query for testing")) {
        ResultSetMetaData metadata = rs.getMetaData();
        assertEquals(metadata.getColumnCount(), 1);
        assertEquals(metadata.getColumnName(1), "_col0");
        assertTrue(rs.next());
        assertEquals(rs.getLong(1), 253161L);
        assertEquals(rs.getLong("_col0"), 253161L);
      assertGreaterThanOrEqual(queryStatsList.size(), 5); // duplicate stats is possible
      assertEquals(queryStatsList.get(0).getState(), "QUEUED");
      assertEquals(queryStatsList.get(queryStatsList.size() - 1).getState(), "FINISHED");

代码示例来源:origin: prestodb/presto

@Test
public void testInvalidResponses()
    throws Exception
  TestingClientCallback callback = new TestingClientCallback(requestComplete);
  client.scheduleRequest();
  requestComplete.await(10, TimeUnit.SECONDS);
  assertEquals(callback.getPages().size(), 0);
  assertEquals(callback.getCompletedRequests(), 1);
  assertEquals(callback.getFinishedBuffers(), 0);
  assertEquals(callback.getFailedBuffers(), 1);
  assertInstanceOf(callback.getFailure(), PageTransportErrorException.class);
  assertContains(callback.getFailure().getMessage(), "Expected response code to be 200, but was 404 Not Found");
  assertStatus(client, location, "queued", 0, 1, 1, 1, "not scheduled");
  assertEquals(callback.getFinishedBuffers(), 0);
  assertEquals(callback.getFailedBuffers(), 1);
  assertInstanceOf(callback.getFailure(), PageTransportErrorException.class);
  assertContains(callback.getFailure().getMessage(), "Expected application/x-presto-pages response from server but got INVALID_TYPE");
  assertStatus(client, location, "queued", 0, 2, 2, 2, "not scheduled");
  assertEquals(callback.getFinishedBuffers(), 0);
  assertEquals(callback.getFailedBuffers(), 1);
  assertInstanceOf(callback.getFailure(), PageTransportErrorException.class);
  assertContains(callback.getFailure().getMessage(), "Expected application/x-presto-pages response from server but got text/plain");
  assertStatus(client, location, "queued", 0, 3, 3, 3, "not scheduled");

代码示例来源:origin: prestodb/presto

@Test
public void testOrdering()
{
  Iterator<StandardErrorCode> iterator = asList(StandardErrorCode.values()).iterator();
  assertTrue(iterator.hasNext());
  int previous = code(iterator.next());
  while (iterator.hasNext()) {
    StandardErrorCode code = iterator.next();
    int current = code(code);
    assertGreaterThan(current, previous, "Code is out of order: " + code);
    if ((code != GENERIC_INTERNAL_ERROR) && (code != GENERIC_INSUFFICIENT_RESOURCES)) {
      assertEquals(current, previous + 1, "Code is not sequential: " + code);
    }
    previous = current;
  }
}

代码示例来源:origin: prestodb/presto

@Test
public void testBufferLimit()
  MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize);
  URI location = URI.create("http://localhost:8080");
  assertEquals(exchangeClient.isClosed(), false);
    assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
    sleepUninterruptibly(100, MILLISECONDS);
  assertEquals(exchangeClient.getStatus().getBufferedPages(), 1);
  assertTrue(exchangeClient.getStatus().getBufferedBytes() > 0);
  assertStatus(exchangeClient.getStatus().getPageBufferClientStatuses().get(0), location, "queued", 1, 1, 1, "not scheduled");
    assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
    sleepUninterruptibly(100, MILLISECONDS);
    assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
    sleepUninterruptibly(100, MILLISECONDS);

代码示例来源:origin: prestodb/presto

@Test
public void testWriteOutputStreamsInOrder()
    throws IOException
    OrcWriter writer = new OrcWriter(
        new OutputStreamOrcDataSink(new FileOutputStream(tempFile.getFile())),
        ImmutableList.of("test1", "test2", "test3", "test4", "test5"),
        ImmutableList.of(VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR),
        ORC,
        NONE,
            .withRowGroupMaxRowCount(ORC_ROW_GROUP_SIZE)
            .withDictionaryMaxMemory(new DataSize(32, MEGABYTE)),
        ImmutableMap.of(),
        HIVE_STORAGE_TIME_ZONE,
        true,
        for (Stream stream : stripeFooter.getStreams()) {
          if (isIndexStream(stream)) {
            assertFalse(dataStreamStarted);
            continue;
          assertGreaterThanOrEqual(stream.getLength(), size);
          size = stream.getLength();

代码示例来源:origin: prestodb/presto

@Test
public void testSplitPage()
{
  int positionCount = 10;
  int maxPageSizeInBytes = 100;
  List<Type> types = ImmutableList.of(BIGINT, BIGINT, BIGINT);
  Page largePage = createSequencePage(types, positionCount, 0, 1, 1);
  List<Page> pages = splitPage(largePage, maxPageSizeInBytes);
  assertGreaterThan(pages.size(), 1);
  assertPageSize(pages, maxPageSizeInBytes);
  assertPositionCount(pages, positionCount);
  MaterializedResult actual = toMaterializedResult(TEST_SESSION, types, pages);
  MaterializedResult expected = toMaterializedResult(TEST_SESSION, types, ImmutableList.of(largePage));
  assertEquals(actual, expected);
}

代码示例来源:origin: prestodb/presto

@Test
public void testMismatchedExecutionStrategy()
      2,
      TYPES,
      ImmutableList.of(0),
      Optional.empty(),
      UNGROUPED_EXECUTION,
  try {
    ungroupedLocalExchangeFactory.getLocalExchange(Lifespan.driverGroup(3));
    fail("expected failure");
    assertContains(e.getMessage(), "Driver-group exchange cannot be created.");
      2,
      TYPES,
      ImmutableList.of(0),
      Optional.empty(),
      GROUPED_EXECUTION,
  try {
    groupedLocalExchangeFactory.getLocalExchange(Lifespan.taskWide());
    fail("expected failure");
    assertContains(e.getMessage(), "Task-wide exchange cannot be created.");

代码示例来源:origin: prestodb/presto

@Test
public void testTableScanOperator()
  SourceOperator operator = testPreparer.newTableScanOperator(driverContext);
  assertEquals(driverContext.getSystemMemoryUsage(), 0);
    assertFalse(operator.isFinished());
    Page page = operator.getOutput();
    assertNotNull(page);
    page.getBlock(1);
    if (memoryUsage == -1) {
      memoryUsage = driverContext.getSystemMemoryUsage();
      assertBetweenInclusive(memoryUsage, 460000L, 469999L);
    if (memoryUsage == -1) {
      memoryUsage = driverContext.getSystemMemoryUsage();
      assertBetweenInclusive(memoryUsage, 460000L, 469999L);
    if (memoryUsage == -1) {
      memoryUsage = driverContext.getSystemMemoryUsage();
      assertBetweenInclusive(memoryUsage, 360000L, 369999L);

代码示例来源:origin: prestodb/presto

@Test
public void testCastWithJsonParseOptimization()
  Signature jsonParseSignature = new Signature("json_parse", SCALAR, JSON.getTypeSignature(), ImmutableList.of(VARCHAR.getTypeSignature()));
  Signature jsonCastSignature = new Signature(CAST, SCALAR, parseTypeSignature("array(integer)"), ImmutableList.of(JSON.getTypeSignature()));
  RowExpression jsonCastExpression = new CallExpression(jsonCastSignature, new ArrayType(INTEGER), ImmutableList.of(call(jsonParseSignature, JSON, constant(utf8Slice("[1, 2]"), VARCHAR))));
  RowExpression resultExpression = optimizer.optimize(jsonCastExpression);
  assertInstanceOf(resultExpression, ConstantExpression.class);
  Object resultValue = ((ConstantExpression) resultExpression).getValue();
  assertInstanceOf(resultValue, IntArrayBlock.class);
  assertEquals(toValues(INTEGER, (IntArrayBlock) resultValue), ImmutableList.of(1, 2));
  jsonCastExpression = new CallExpression(jsonCastSignature, new ArrayType(VARCHAR), ImmutableList.of(call(jsonParseSignature, JSON, field(1, VARCHAR))));
  resultExpression = optimizer.optimize(jsonCastExpression);
  assertEquals(
      resultExpression,
      call(internalScalarFunction(JSON_STRING_TO_ARRAY_NAME, parseTypeSignature("array(varchar)"), parseTypeSignature(StandardTypes.VARCHAR)), new ArrayType(VARCHAR), field(1, VARCHAR)));
  jsonCastExpression = new CallExpression(jsonCastSignature, mapType(INTEGER, VARCHAR), ImmutableList.of(call(jsonParseSignature, JSON, field(1, VARCHAR))));
  resultExpression = optimizer.optimize(jsonCastExpression);
  assertEquals(
      resultExpression,
      call(internalScalarFunction(JSON_STRING_TO_MAP_NAME, parseTypeSignature("map(integer,varchar)"), parseTypeSignature(StandardTypes.VARCHAR)), mapType(INTEGER, VARCHAR), field(1, VARCHAR)));

代码示例来源:origin: prestodb/presto

@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);
}

代码示例来源:origin: prestodb/presto

@Test
public void testRowNumberUnpartitioned()
      0,
      new PlanNodeId("test"),
      ImmutableList.of(BIGINT, DOUBLE),
      Ints.asList(1, 0),
      Ints.asList(),
      ImmutableList.of(),
      Optional.empty(),
      Optional.empty(),
  assertEquals(rowNumberColumn.getPositionCount(), 10);
  MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(DOUBLE, BIGINT), pages);
  assertEqualsIgnoreOrder(actual.getMaterializedRows(), expectedResult.getMaterializedRows());

代码示例来源:origin: prestodb/presto

@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);
}

代码示例来源:origin: prestodb/presto

@Test
public void testWrapWithCacheIfTinyStripes()
      ImmutableList.of(),
      maxMergeDistance,
      tinyStripeThreshold);
  assertInstanceOf(actual, CachingOrcDataSource.class);
      ImmutableList.of(new StripeInformation(123, 3, 10, 10, 10)),
      maxMergeDistance,
      tinyStripeThreshold);
  assertInstanceOf(actual, CachingOrcDataSource.class);
      ImmutableList.of(new StripeInformation(123, 3, 10, 10, 10), new StripeInformation(123, 33, 10, 10, 10), new StripeInformation(123, 63, 10, 10, 10)),
      maxMergeDistance,
      tinyStripeThreshold);
  assertInstanceOf(actual, CachingOrcDataSource.class);
      maxMergeDistance,
      tinyStripeThreshold);
  assertInstanceOf(actual, CachingOrcDataSource.class);

相关文章