use of co.cask.cdap.internal.io.ReflectionSchemaGenerator in project cdap by caskdata.
the class ReflectionTableTest method testPutAndGet.
@Test
public void testPutAndGet() throws Exception {
dsFrameworkUtil.createInstance("table", users, DatasetProperties.builder().build());
try {
final Table usersTable = dsFrameworkUtil.getInstance(users);
final byte[] rowKey = Bytes.toBytes(123);
final Schema schema = new ReflectionSchemaGenerator().generate(User.class);
assertGetAndPut(usersTable, rowKey, SAMUEL, schema);
} finally {
dsFrameworkUtil.deleteInstance(users);
}
}
use of co.cask.cdap.internal.io.ReflectionSchemaGenerator in project cdap by caskdata.
the class ReflectionTableTest method testStructuredRecordProjection.
@Test
public void testStructuredRecordProjection() throws Exception {
dsFrameworkUtil.createInstance("table", users, DatasetProperties.builder().build());
try {
final Table usersTable = dsFrameworkUtil.getInstance(users);
final byte[] rowKey = Bytes.toBytes(123);
final User2 projected = new User2("Samuel L.", 123L, ((Float) 50000000.02f).doubleValue(), Double.MAX_VALUE, ByteBuffer.wrap(new byte[] { 0, 1, 2 }));
final Schema fullSchema = new ReflectionSchemaGenerator().generate(User.class);
final Schema projSchema = new ReflectionSchemaGenerator().generate(User2.class);
// TableDataset is not accessible here, but we know that's the underlying implementation...
TransactionExecutor tx = dsFrameworkUtil.newTransactionExecutor((TransactionAware) usersTable);
tx.execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() throws Exception {
Put put = new Put(rowKey);
ReflectionPutWriter<User> putWriter = new ReflectionPutWriter<>(fullSchema);
putWriter.write(SAMUEL, put);
usersTable.put(put);
Row row = usersTable.get(rowKey);
ReflectionRowRecordReader rowReader = new ReflectionRowRecordReader(projSchema, null);
StructuredRecord actual = rowReader.read(row, fullSchema);
assertRecordEqualsUser(projected, actual);
}
});
} finally {
dsFrameworkUtil.deleteInstance(users);
}
}
use of co.cask.cdap.internal.io.ReflectionSchemaGenerator in project cdap by caskdata.
the class ApplicationVerificationTest method testGoodApplication.
/**
* Good test
*/
@Test
public void testGoodApplication() throws Exception {
ApplicationSpecification appSpec = Specifications.from(new WebCrawlApp());
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
ApplicationVerification app = new ApplicationVerification();
VerifyResult result = app.verify(new ApplicationId("test", newSpec.getName()), newSpec);
Assert.assertTrue(result.getMessage(), result.getStatus() == VerifyResult.Status.SUCCESS);
}
use of co.cask.cdap.internal.io.ReflectionSchemaGenerator in project cdap by caskdata.
the class FlowVerificationTest method testFlowMissingConnection.
/**
* This test that verification of flow connections
*/
@Test
public void testFlowMissingConnection() throws Exception {
ApplicationSpecification appSpec = Specifications.from(new NoConsumerApp());
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
FlowVerification flowVerifier = new FlowVerification();
for (FlowSpecification flowSpec : appSpec.getFlows().values()) {
VerifyResult result = flowVerifier.verify(new ApplicationId("test", newSpec.getName()), flowSpec);
Assert.assertTrue(result.getStatus() == VerifyResult.Status.FAILED);
}
}
use of co.cask.cdap.internal.io.ReflectionSchemaGenerator in project cdap by caskdata.
the class FlowVerificationTest method testFlowWithMoreOutputThanWhatInputCanHandle.
@Test
public void testFlowWithMoreOutputThanWhatInputCanHandle() throws Exception {
ApplicationSpecification appSpec = Specifications.from(new WebCrawlApp());
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
FlowVerification flowSpec = new FlowVerification();
for (Map.Entry<String, FlowSpecification> entry : newSpec.getFlows().entrySet()) {
VerifyResult result = flowSpec.verify(new ApplicationId("test", newSpec.getName()), entry.getValue());
// that is not connected to any input to flowlet CountByField.
if (entry.getValue().getName().equals("WordCountFlow")) {
Assert.assertTrue(result.getStatus() == VerifyResult.Status.FAILED);
} else {
Assert.assertTrue(result.getStatus() == VerifyResult.Status.SUCCESS);
}
}
}
Aggregations