@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); }
@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(); } }
.withTableId(TABLE_ID) .withProjectId(PROJECT_ID) .withBigtableOptions(new BigtableOptions.Builder().setInstanceId("instance_id").build()) .isDataAccessible()); assertTrue( .withTableId(TABLE_ID) .withInstanceId(INSTANCE_ID) .withBigtableOptions(new BigtableOptions.Builder().setProjectId("project_id").build()) .isDataAccessible()); assertTrue( .withTableId(TABLE_ID) .withBigtableOptions( new BigtableOptions.Builder() .setProjectId("project_id") .setInstanceId("instance_id")
@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(); }
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; }
/** * <p>toBuilder.</p> * * @return a {@link com.google.cloud.bigtable.config.BigtableOptions.Builder} object. */ public Builder toBuilder() { return new Builder(this); }
public static Builder builder() { return new Builder(); } /**
@Test public void testReadValidationFailsMissingInstanceIdAndProjectId() { BigtableIO.Read read = BigtableIO.read() .withTableId("table") .withBigtableOptions(new BigtableOptions.Builder().build()); thrown.expect(IllegalArgumentException.class); read.expand(null); }
@Test public void testWriteValidationFailsMissingProjectId() { BigtableIO.Write write = BigtableIO.write() .withTableId("table") .withInstanceId("instance") .withBigtableOptions(new BigtableOptions.Builder().build()); thrown.expect(IllegalArgumentException.class); write.expand(null); }
@Test public void testWriteValidationFailsMissingInstanceIdAndProjectId() { BigtableIO.Write write = BigtableIO.write() .withTableId("table") .withBigtableOptions(new BigtableOptions.Builder().build()); thrown.expect(IllegalArgumentException.class); write.expand(null); }
@Test public void testReadValidationFailsMissingInstanceId() { BigtableIO.Read read = BigtableIO.read() .withTableId("table") .withProjectId("project") .withBigtableOptions(new BigtableOptions.Builder().build()); thrown.expect(IllegalArgumentException.class); read.expand(null); }
@Test public void testWriteValidationFailsMissingInstanceId() { BigtableIO.Write write = BigtableIO.write() .withTableId("table") .withProjectId("project") .withBigtableOptions(new BigtableOptions.Builder().build()); thrown.expect(IllegalArgumentException.class); write.expand(null); }
@Test public void testReadValidationFailsMissingProjectId() { BigtableIO.Read read = BigtableIO.read() .withTableId("table") .withInstanceId("instance") .withBigtableOptions(new BigtableOptions.Builder().build()); thrown.expect(IllegalArgumentException.class); read.expand(null); }