@Test(groups = "requiresTempFile")
  public void testAliasedBindingBindsCorrectly() {
    final String prefix = "test";
    Map<String, String> properties =
        createDefaultConfigurationProperties(prefix, temporaryFile.getAbsolutePath());

    Injector injector =
        createInjector(
            properties,
            new H2EmbeddedDataSourceModule(prefix, MainBinding.class, AliasBinding.class),
            new Module() {
              @Override
              public void configure(Binder binder) {
                binder.bind(TwoObjectsHolder.class);
              }
            });

    ObjectHolder objectHolder = injector.getInstance(ObjectHolder.class);
    TwoObjectsHolder twoObjectsHolder = injector.getInstance(TwoObjectsHolder.class);

    // Held data source objects should all be of the correct type
    Assertions.assertInstanceOf(twoObjectsHolder.mainDataSource, H2EmbeddedDataSource.class);
    Assertions.assertInstanceOf(twoObjectsHolder.aliasedDataSource, H2EmbeddedDataSource.class);

    // And should all be references to the same object
    assertSame(objectHolder.dataSource, twoObjectsHolder.mainDataSource);
    assertSame(objectHolder.dataSource, twoObjectsHolder.aliasedDataSource);
  }
Ejemplo n.º 2
0
 private static void assertRecordCursorType(RecordCursor cursor, String fileType) {
   if (fileType.equals("rcfile-text")) {
     assertInstanceOf(cursor, ColumnarTextHiveRecordCursor.class, fileType);
   } else if (fileType.equals("rcfile-binary")) {
     assertInstanceOf(cursor, ColumnarBinaryHiveRecordCursor.class, fileType);
   } else {
     assertInstanceOf(cursor, GenericHiveRecordCursor.class, fileType);
   }
 }
Ejemplo n.º 3
0
 @Override
 public ConnectorPageSource createPageSource(
     Session session, Split split, List<ColumnHandle> columns) {
   assertInstanceOf(split.getConnectorSplit(), FunctionAssertions.TestSplit.class);
   FunctionAssertions.TestSplit testSplit =
       (FunctionAssertions.TestSplit) split.getConnectorSplit();
   if (testSplit.isRecordSet()) {
     RecordSet records =
         InMemoryRecordSet.builder(
                 ImmutableList.<Type>of(
                     BIGINT,
                     VARCHAR,
                     DOUBLE,
                     BOOLEAN,
                     BIGINT,
                     VARCHAR,
                     VARCHAR,
                     TIMESTAMP_WITH_TIME_ZONE))
             .addRow(
                 1234L,
                 "hello",
                 12.34,
                 true,
                 new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC).getMillis(),
                 "%el%",
                 null,
                 packDateTimeWithZone(
                     new DateTime(1970, 1, 1, 0, 1, 0, 999, DateTimeZone.UTC).getMillis(),
                     TimeZoneKey.getTimeZoneKey("Z")))
             .build();
     return new RecordPageSource(records);
   } else {
     return new FixedPageSource(ImmutableList.of(SOURCE_PAGE));
   }
 }
  @Test(groups = "requiresTempFile")
  public void testCorrectConfigurationPrefix() {
    final String expectedPrefix = "expected";
    final String otherPrefix = "additional";

    final String propertySuffixToTest = ".db.connections.max";
    final int expectedValue = 1234;

    // Required properties for construction
    Map<String, String> properties =
        createDefaultConfigurationProperties(expectedPrefix, temporaryFile.getAbsolutePath());

    // Optional property added with two different prefixes, two different values
    properties.put(otherPrefix + propertySuffixToTest, Integer.toString(expectedValue + 5678));
    properties.put(expectedPrefix + propertySuffixToTest, Integer.toString(expectedValue));

    Injector injector =
        createInjector(
            properties, new H2EmbeddedDataSourceModule(expectedPrefix, MainBinding.class));

    ObjectHolder objectHolder = injector.getInstance(ObjectHolder.class);

    // Make sure we picked up the value with the expected prefix
    Assertions.assertInstanceOf(objectHolder.dataSource, H2EmbeddedDataSource.class);

    H2EmbeddedDataSource created = (H2EmbeddedDataSource) objectHolder.dataSource;

    assertEquals(
        created.getMaxConnections(),
        expectedValue,
        "Property value not loaded from correct prefix");
  }
Ejemplo n.º 5
0
  protected void assertExpectedPartitions(List<ConnectorPartition> actualPartitions) {
    Map<String, ConnectorPartition> actualById = uniqueIndex(actualPartitions, partitionIdGetter());
    for (ConnectorPartition expected : partitions) {
      assertInstanceOf(expected, HivePartition.class);
      HivePartition expectedPartition = (HivePartition) expected;

      ConnectorPartition 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());
      assertEquals(actualPartition.getBucket(), expectedPartition.getBucket());
      assertEquals(actualPartition.getTupleDomain(), expectedPartition.getTupleDomain());
    }
  }
  @Test(groups = "requiresTempFile")
  public void testObjectBindingFromInjector() {
    final String prefix = "test";
    Map<String, String> properties =
        createDefaultConfigurationProperties(prefix, temporaryFile.getAbsolutePath());

    Injector injector =
        createInjector(properties, new H2EmbeddedDataSourceModule(prefix, MainBinding.class));

    ObjectHolder objectHolder = injector.getInstance(ObjectHolder.class);

    Assertions.assertInstanceOf(objectHolder.dataSource, H2EmbeddedDataSource.class);
  }
Ejemplo n.º 7
0
  @BeforeClass
  public void setup() throws Exception {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra();

    initializeTestData(DATE);

    String connectorId = "cassandra-test";
    CassandraConnectorFactory connectorFactory =
        new CassandraConnectorFactory(connectorId, ImmutableMap.<String, String>of());

    Connector connector =
        connectorFactory.create(
            connectorId,
            ImmutableMap.of(
                "cassandra.contact-points",
                HOSTNAME,
                "cassandra.native-protocol-port",
                Integer.toString(PORT)));

    metadata = connector.getMetadata();
    assertInstanceOf(metadata, CassandraMetadata.class);

    splitManager = connector.getSplitManager();
    assertInstanceOf(splitManager, CassandraSplitManager.class);

    recordSetProvider = connector.getRecordSetProvider();
    assertInstanceOf(recordSetProvider, CassandraRecordSetProvider.class);

    ConnectorHandleResolver handleResolver = connector.getHandleResolver();
    assertInstanceOf(handleResolver, CassandraHandleResolver.class);

    database = KEYSPACE_NAME.toLowerCase();
    table = new SchemaTableName(database, TABLE_NAME.toLowerCase());
    tableUnpartitioned = new SchemaTableName(database, "presto_test_unpartitioned");
    invalidTable = new SchemaTableName(database, "totally_invalid_table_name");
  }
Ejemplo n.º 8
0
  @Test
  public void testExternalBatches() {
    assertFalse(dao.externalBatchExists("foo"));
    assertFalse(dao.externalBatchExists("bar"));

    dao.insertExternalBatch("foo");

    assertTrue(dao.externalBatchExists("foo"));
    assertFalse(dao.externalBatchExists("bar"));

    try {
      dao.insertExternalBatch("foo");
      fail("expected exception");
    } catch (UnableToExecuteStatementException e) {
      assertInstanceOf(e.getCause(), SQLException.class);
      assertTrue(((SQLException) e.getCause()).getSQLState().startsWith("23"));
    }
  }
  @Test
  public void testExceptionFromResponseHandler() throws Exception {
    TestingTicker ticker = new TestingTicker();
    AtomicReference<Duration> tickerIncrement =
        new AtomicReference<>(new Duration(0, TimeUnit.SECONDS));

    TestingHttpClient.Processor processor =
        (input) -> {
          Duration delta = tickerIncrement.get();
          ticker.increment(delta.toMillis(), TimeUnit.MILLISECONDS);
          throw new RuntimeException("Foo");
        };

    CyclicBarrier requestComplete = new CyclicBarrier(2);
    TestingClientCallback callback = new TestingClientCallback(requestComplete);

    URI location = URI.create("http://localhost:8080");
    HttpPageBufferClient client =
        new HttpPageBufferClient(
            new TestingHttpClient(processor, executor),
            new DataSize(10, Unit.MEGABYTE),
            new Duration(1, TimeUnit.MINUTES),
            location,
            callback,
            blockEncodingManager,
            executor,
            Stopwatch.createUnstarted(ticker));

    assertStatus(client, location, "queued", 0, 0, 0, 0, "not scheduled");

    // request processor will throw exception, verify the request is marked a completed
    // this starts the error stopwatch
    client.scheduleRequest();
    requestComplete.await(10, TimeUnit.SECONDS);
    assertEquals(callback.getPages().size(), 0);
    assertEquals(callback.getCompletedRequests(), 1);
    assertEquals(callback.getFinishedBuffers(), 0);
    assertEquals(callback.getFailedBuffers(), 0);
    assertStatus(client, location, "queued", 0, 1, 1, 1, "not scheduled");

    // advance time forward, but not enough to fail the client
    tickerIncrement.set(new Duration(30, TimeUnit.SECONDS));

    // verify that the client has not failed
    client.scheduleRequest();
    requestComplete.await(10, TimeUnit.SECONDS);
    assertEquals(callback.getPages().size(), 0);
    assertEquals(callback.getCompletedRequests(), 2);
    assertEquals(callback.getFinishedBuffers(), 0);
    assertEquals(callback.getFailedBuffers(), 0);
    assertStatus(client, location, "queued", 0, 2, 2, 2, "not scheduled");

    // advance time forward beyond the minimum error duration
    tickerIncrement.set(new Duration(31, TimeUnit.SECONDS));

    // verify that the client has failed
    client.scheduleRequest();
    requestComplete.await(10, TimeUnit.SECONDS);
    assertEquals(callback.getPages().size(), 0);
    assertEquals(callback.getCompletedRequests(), 3);
    assertEquals(callback.getFinishedBuffers(), 0);
    assertEquals(callback.getFailedBuffers(), 1);
    assertInstanceOf(callback.getFailure(), PageTransportTimeoutException.class);
    assertContains(
        callback.getFailure().getMessage(),
        WORKER_NODE_ERROR + " (http://localhost:8080/0 - requests failed for 61.00s)");
    assertStatus(client, location, "queued", 0, 3, 3, 3, "not scheduled");
  }
Ejemplo n.º 10
0
  @Test
  public void testInvalidResponses() throws Exception {
    CyclicBarrier beforeRequest = new CyclicBarrier(1);
    CyclicBarrier afterRequest = new CyclicBarrier(1);
    StaticRequestProcessor processor = new StaticRequestProcessor(beforeRequest, afterRequest);

    CyclicBarrier requestComplete = new CyclicBarrier(2);
    TestingClientCallback callback = new TestingClientCallback(requestComplete);

    URI location = URI.create("http://localhost:8080");
    HttpPageBufferClient client =
        new HttpPageBufferClient(
            new TestingHttpClient(processor, executor),
            new DataSize(10, Unit.MEGABYTE),
            new Duration(1, TimeUnit.MINUTES),
            location,
            callback,
            blockEncodingManager,
            executor,
            Stopwatch.createUnstarted());

    assertStatus(client, location, "queued", 0, 0, 0, 0, "not scheduled");

    // send not found response and verify response was ignored
    processor.setResponse(
        new TestingResponse(
            HttpStatus.NOT_FOUND,
            ImmutableListMultimap.of(CONTENT_TYPE, PRESTO_PAGES),
            new byte[0]));
    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");

    // send invalid content type response and verify response was ignored
    callback.resetStats();
    processor.setResponse(
        new TestingResponse(
            HttpStatus.OK, ImmutableListMultimap.of(CONTENT_TYPE, "INVALID_TYPE"), new byte[0]));
    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 application/x-presto-pages response from server but got INVALID_TYPE");
    assertStatus(client, location, "queued", 0, 2, 2, 2, "not scheduled");

    // send unexpected content type response and verify response was ignored
    callback.resetStats();
    processor.setResponse(
        new TestingResponse(
            HttpStatus.OK, ImmutableListMultimap.of(CONTENT_TYPE, "text/plain"), new byte[0]));
    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 application/x-presto-pages response from server but got text/plain");
    assertStatus(client, location, "queued", 0, 3, 3, 3, "not scheduled");

    // close client and verify
    client.close();
    requestComplete.await(10, TimeUnit.SECONDS);
    assertStatus(client, location, "closed", 0, 3, 4, 3, "not scheduled");
  }