@Before public void setup() { MockitoAnnotations.initMocks(this); BigtableOptions options = new BigtableOptions.Builder().setProjectId("project").setInstanceId("instance").build(); when(mockSession.getOptions()).thenReturn(options); when(mockSession.createBulkMutation(eq(TABLE_NAME))).thenReturn(mockBulkMutation); when(mockSession.getDataClient()).thenReturn(mockBigtableDataClient); }
bigtableOptionsBuilder.setInstanceId(getValue(configuration, INSTANCE_ID_KEY, "Instance ID")); String appProfileId = configuration.get(APP_PROFILE_ID_KEY, null); if (appProfileId != null) {
bigtableOptionsBuilder.setInstanceId(getValue(configuration, INSTANCE_ID_KEY, "Instance ID")); String appProfileId = configuration.get(APP_PROFILE_ID_KEY, null); if (appProfileId != null) {
.withTableId(TABLE_ID) .withProjectId(PROJECT_ID) .withBigtableOptions(new BigtableOptions.Builder().setInstanceId("instance_id").build()) .isDataAccessible()); assertTrue( new BigtableOptions.Builder() .setProjectId("project_id") .setInstanceId("instance_id") .build()) .isDataAccessible());
@Before public void setup() throws Exception { PipelineOptionsFactory.register(BigtableTestOptions.class); options = TestPipeline.testingPipelineOptions().as(BigtableTestOptions.class); project = options.as(GcpOptions.class).getProject(); bigtableOptions = new Builder() .setProjectId(project) .setInstanceId(options.getInstanceId()) .setUserAgent("apache-beam-test") .build(); session = new BigtableSession( bigtableOptions .toBuilder() .setCredentialOptions( CredentialOptions.credential(options.as(GcpOptions.class).getGcpCredential())) .build()); tableAdminClient = session.getTableAdminClient(); }
@Test public void testE2EBigtableRead() throws Exception { PipelineOptionsFactory.register(BigtableTestOptions.class); BigtableTestOptions options = TestPipeline.testingPipelineOptions().as(BigtableTestOptions.class); String project = options.getBigtableProject(); if (project.equals("")) { project = options.as(GcpOptions.class).getProject(); } BigtableOptions.Builder bigtableOptionsBuilder = new BigtableOptions.Builder().setProjectId(project).setInstanceId(options.getInstanceId()); final String tableId = "BigtableReadTest"; final long numRows = 1000L; Pipeline p = Pipeline.create(options); PCollection<Long> count = p.apply(BigtableIO.read().withBigtableOptions(bigtableOptionsBuilder).withTableId(tableId)) .apply(Count.globally()); PAssert.thatSingleton(count).isEqualTo(numRows); p.run(); } }
@Test public void testGetBigtableServiceWithConfigurator() { SerializableFunction<BigtableOptions.Builder, BigtableOptions.Builder> configurator = (SerializableFunction<BigtableOptions.Builder, BigtableOptions.Builder>) input -> input .setInstanceId(INSTANCE_ID.get() + INSTANCE_ID.get()) .setProjectId(PROJECT_ID.get() + PROJECT_ID.get()) .setBulkOptions(new BulkOptions.Builder().setUseBulkApi(true).build()); BigtableService service = config .withProjectId(PROJECT_ID) .withInstanceId(INSTANCE_ID) .withBigtableOptionsConfigurator(configurator) .getBigtableService(PipelineOptionsFactory.as(GcpOptions.class)); assertEquals(PROJECT_ID.get(), service.getBigtableOptions().getProjectId()); assertEquals(INSTANCE_ID.get(), service.getBigtableOptions().getInstanceId()); assertEquals(true, service.getBigtableOptions().getBulkOptions().useBulkApi()); }
private BigtableOptions.Builder effectiveUserProvidedBigtableOptions() { BigtableOptions.Builder effectiveOptions = getBigtableOptions() != null ? getBigtableOptions().toBuilder() : new BigtableOptions.Builder(); if (getBigtableOptionsConfigurator() != null) { effectiveOptions = getBigtableOptionsConfigurator().apply(effectiveOptions); } if (getInstanceId() != null) { effectiveOptions.setInstanceId(getInstanceId().get()); } if (getProjectId() != null) { effectiveOptions.setProjectId(getProjectId().get()); } return effectiveOptions; }
/** * Creates a {@link BigtableClusterUtilities} for all instances in a projectId. * * @param projectId * * @return a {@link BigtableClusterUtilities} for a all instances in a projectId. * @throws GeneralSecurityException if ssl configuration fails * @throws IOException if some aspect of the connection fails. */ public static BigtableClusterUtilities forAllInstances(String projectId) throws IOException, GeneralSecurityException { // '-' means all instanceids. return new BigtableClusterUtilities( BigtableOptions.builder().setProjectId(projectId).setInstanceId("-").build()); }
/** * Creates a {@link BigtableClusterUtilities} for a projectId and an instanceId. * * @param projectId * @param instanceId * * @return a {@link BigtableClusterUtilities} for a specific projectId/instanceId. * @throws GeneralSecurityException if ssl configuration fails * @throws IOException if some aspect of the connection fails. */ public static BigtableClusterUtilities forInstance(String projectId, String instanceId) throws IOException, GeneralSecurityException { return new BigtableClusterUtilities( BigtableOptions.builder().setProjectId(projectId).setInstanceId(instanceId).build()); }