Java Code Examples for com.google.inject.util.Providers#of()

The following examples show how to use com.google.inject.util.Providers#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TephraTransactionProvider.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public PhoenixTransactionService getTransactionService(Configuration config, ConnectionInfo connInfo, int port) {
    config.setInt(TxConstants.Service.CFG_DATA_TX_BIND_PORT, port);
    int retryTimeOut = config.getInt(TxConstants.Service.CFG_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC, 
            TxConstants.Service.DEFAULT_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC);
    ZKClientService zkClient = ZKClientServices.delegate(
      ZKClients.reWatchOnExpire(
        ZKClients.retryOnFailure(
          ZKClientService.Builder.of(connInfo.getZookeeperConnectionString())
            .setSessionTimeout(config.getInt(HConstants.ZK_SESSION_TIMEOUT,
                    HConstants.DEFAULT_ZK_SESSION_TIMEOUT))
            .build(),
          RetryStrategies.exponentialDelay(500, retryTimeOut, TimeUnit.MILLISECONDS)
        )
      )
    );

    DiscoveryService discovery = new ZKDiscoveryService(zkClient);
    TransactionManager txManager = new TransactionManager(config, new HDFSTransactionStateStorage(config, 
            new SnapshotCodecProvider(config), new TxMetricsCollector()), new TxMetricsCollector());
    TransactionService txService = new TransactionService(config, zkClient, discovery, Providers.of(txManager));
    TephraTransactionService service = new TephraTransactionService(zkClient, txService);
    service.start();
    return service;
}
 
Example 2
Source File: TestMergingDatabaseDataSetConsumer.java    From morf with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that merging two extracts containing both overlapping and non-overlapping records results in having the overlapping records
 * overwrite the already-present ones and the non-overlapping to be inserted.
 */
@Test
@Parameters(method = "mergeParameters")
public void testMergeTwoExtracts(File controlExtract, File initialDataset, File datasetToMerge) throws IOException {
  // GIVEN

  // ... a control extract (provided)

  // ... a database with some data
  SqlScriptExecutorProvider sqlScriptExecutorProvider = new SqlScriptExecutorProvider(connectionResources.getDataSource(), Providers.of(connectionResources.sqlDialect()));

  log.info("Creating the initial DataSet");

  DataSetConsumer firstDatabaseDataSetConsumer = new SchemaModificationAdapter(new DatabaseDataSetConsumer(connectionResources, sqlScriptExecutorProvider));
  new DataSetConnector(toDataSetProducer(initialDataset), firstDatabaseDataSetConsumer).connect();

  log.info("Initial DataSet creation complete");

  // WHEN

  // ... we merge a datasource having both overlapping and non-overlapping tables and records into it

  DataSetConsumer mergingDatabaseDatasetConsumer = new MergingDatabaseDataSetConsumer(connectionResources, sqlScriptExecutorProvider);
  new DataSetConnector(toDataSetProducer(datasetToMerge), mergingDatabaseDatasetConsumer).connect();

  // ... and we pipe the result into a zip file
  log.info("Creating an XML extract from the merged database tables.");
  File mergedExtractsAsFile = getDatabaseAsFile();
  log.info("Merged XML file creation complete.");

  // THEN

  // ... the resulting dataset matches the control one
  assertThat("the merged dataset should match the control one", mergedExtractsAsFile, sameXmlFileAndLengths(controlExtract));
}
 
Example 3
Source File: EvaluateStatementTest.java    From yql-plus with Apache License 2.0 5 votes vote down vote up
@Override
public ModuleType findModule(Location location, ContextPlanner planner, List<String> modulePath) {
    String name = Joiner.on(".").join(modulePath);
    if("test".equals(name)) {
        Provider<Exports> moduleProvider = Providers.of(new TestModule());
        ExportUnitGenerator adapter = new ExportUnitGenerator(planner.getGambitScope());
        return adapter.apply(modulePath, moduleProvider);
    }
    return super.findModule(location, planner, modulePath);
}
 
Example 4
Source File: SettingsManagerTest.java    From emodb with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void setUp() {
    _dataStore = new InMemoryDataStore(new MetricRegistry());
    _cacheRegistry = mock(CacheRegistry.class);
    _cacheHandle = mock(CacheHandle.class);
    when(_cacheRegistry.register(eq("settings"), any(Cache.class), eq(true))).thenReturn(_cacheHandle);

    _settingsManager = new SettingsManager(Providers.of(_dataStore), "__system:settings",
            "app_global:sys", _cacheRegistry);
}
 
Example 5
Source File: RaptureWebResourceBundleTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() {
  BaseUrlHolder.set("http://baseurl/");

  when(httpServletRequest.getParameter("debug")).thenReturn("false");

  underTest =
      new RaptureWebResourceBundle(applicationVersion, Providers.of(httpServletRequest), Providers.of(stateComponent),
          templateHelper, asList(new UiPluginDescriptorImpl()),
          asList(new ExtJsUiPluginDescriptorImpl("test-1"), new ExtJsUiPluginDescriptorImpl("test-2")));
}
 
Example 6
Source File: ShiroKerberosPermissiveAuthenticationFilterTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  mockServlet = createMock(HttpServlet.class);

  filter =
      new ShiroKerberosPermissiveAuthenticationFilter(Providers.of(createMock(Subject.class)));
}
 
Example 7
Source File: ShiroKerberosAuthenticationFilterTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  subject = createMock(Subject.class);
  mockServlet = createMock(HttpServlet.class);

  filter = new ShiroKerberosAuthenticationFilter(Providers.of(subject));
}
 
Example 8
Source File: SabotNode.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
ContextService getContextService(
        Provider<ClusterCoordinator> clusterCoordinator,
        Provider<GroupResourceInformation> resourceInformation,
        Provider<WorkStats> workStats,
        Provider<LegacyKVStoreProvider> kvStoreProvider,
        Provider<FabricService> fabricService,
        Provider<ConduitServer> conduitServer,
        Provider<UserServer> userServer,
        Provider<MaterializationDescriptorProvider> materializationDescriptorProvider,
        Provider<QueryObserverFactory> queryObserverFactory,
        Provider<AccelerationManager> accelerationManager,
        Provider<AccelerationListManager> accelerationListManager,
        Provider<NamespaceService.Factory> namespaceServiceFactory,
        Provider<DatasetListingService> datasetListingService,
        Provider<UserService> userService,
        Provider<CatalogService> catalogService,
        Provider<ConduitProvider> conduitProvider,
        Provider<SpillService> spillService,
        Provider<ConnectionReader> connectionReader,
        Provider<OptionManager> optionManagerProvider,
        Provider<SystemOptionManager> systemOptionManagerProvider,
        Provider<OptionValidatorListing> optionValidatorListingProvider
) {
  return new ContextService(
          bootstrap,
          clusterCoordinator,
          resourceInformation,
          workStats,
          kvStoreProvider,
          fabricService,
          conduitServer,
          userServer,
          materializationDescriptorProvider,
          queryObserverFactory,
          accelerationManager,
          accelerationListManager,
          namespaceServiceFactory,
          datasetListingService,
          userService,
          catalogService,
          conduitProvider,
          Providers.of(null),
          spillService,
          connectionReader,
          CredentialsService::new,
          () -> JobResultInfoProvider.NOOP,
          optionManagerProvider,
          systemOptionManagerProvider,
          Providers.of(null),
          Providers.of(null),
          optionValidatorListingProvider,
          allRoles
  );
}
 
Example 9
Source File: TableLoaderBuilder.java    From morf with Apache License 2.0 4 votes vote down vote up
@Override
public TableLoaderBuilder withDialect(SqlDialect sqlDialect) {
  this.sqlDialect = Providers.of(sqlDialect);
  return this;
}
 
Example 10
Source File: SqlScriptExecutorProvider.java    From morf with Apache License 2.0 4 votes vote down vote up
/**
 * @param dataSource The database connection source to use
 * @param sqlDialect The dialect to use for the dataSource
 */
public SqlScriptExecutorProvider(final DataSource dataSource, SqlDialect sqlDialect) {
  super();
  this.dataSource = dataSource;
  this.sqlDialect = Providers.<SqlDialect>of(sqlDialect);
}
 
Example 11
Source File: TestDatabaseDataSetConsumer.java    From morf with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that blob fields are added to the the prepared insert statement in correct decoded form.
 *
 * @throws SQLException not really thrown
 */
@Test
public void testBlobInsertion() throws SQLException {

  // Mock all the resources - we're only interested in the PreparedStatement
  // for this test.
  final ConnectionResources connectionResources = Mockito.mock(ConnectionResources.class);
  final DataSource dataSource = Mockito.mock(DataSource.class);
  final Connection connection = Mockito.mock(Connection.class);
  final SqlDialect dialect = Mockito.mock(SqlDialect.class);
  final PreparedStatement statement = Mockito.mock(PreparedStatement.class);
  final java.sql.Blob blob = Mockito.mock(java.sql.Blob.class);
  Mockito.when(statement.getConnection()).thenReturn(connection);
  Mockito.when(connection.createBlob()).thenReturn(blob);
  Mockito.when(blob.setBytes(eq(1L), any(byte[].class))).thenAnswer(invocation -> ((byte[]) invocation.getArguments()[1]).length);
  Mockito.when(connectionResources.getDataSource()).thenReturn(dataSource);
  Mockito.when(dataSource.getConnection()).thenReturn(connection);
  Mockito.when(connectionResources.sqlDialect()).thenReturn(dialect);
  Mockito.when(dialect.convertStatementToSQL(Mockito.any(InsertStatement.class), Mockito.any(Schema.class))).thenReturn("Foo :id :version :blob");
  Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(statement);

  // Create our consumer
  final DatabaseDataSetConsumer consumer = new DatabaseDataSetConsumer(connectionResources, new SqlScriptExecutorProvider(dataSource, Providers.of(dialect)));
  consumer.open();

  // Create a mock schema and records
  final Table table = table("DatabaseTest")
    .columns(
      idColumn(),
      versionColumn(),
      column("blob", DataType.BLOB)
    );
  final List<Record> records = new ArrayList<>();
  records.add(record().setInteger(idColumn().getName(), 1).setInteger(versionColumn().getName(), 2).setString("blob", "QUJD"));

  // consume the records
  consumer.table(table, records);

  // Verify dialect is requested to write the values to the statement

  Mockito.verify(dialect).prepareStatementParameters(any(NamedParameterPreparedStatement.class), parametersCaptor.capture(), valuesCaptor.capture());

  assertThat(FluentIterable.from(parametersCaptor.getValue()).transform(SqlParameter::getImpliedName), contains(
    idColumn().getName(),
    versionColumn().getName(),
    "blob")
  );
  assertThat(valuesCaptor.getValue().getInteger(idColumn().getName()), equalTo(1));
  assertThat(valuesCaptor.getValue().getInteger(versionColumn().getName()), equalTo(2));
  assertThat(valuesCaptor.getValue().getString("blob"), equalTo("QUJD"));
}
 
Example 12
Source File: OrientKeyStoreStorageManagerTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Before
public void setUp() {
  when(db.acquire()).thenReturn(tx);
  storageManager = new OrientKeyStoreStorageManager(Providers.of(db), entityAdapter, eventManager);
}