use of org.bboxdb.network.packages.request.CreateTableRequest in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeCreateTable.
/**
* The the encoding and decoding of an create table package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeCreateTable() throws IOException, PackageEncodeException {
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final TupleStoreConfiguration ssTableConfiguration = TupleStoreConfigurationBuilder.create().withTTL(10, TimeUnit.MILLISECONDS).withVersions(666).withSpatialIndexReader("reader").withSpatialIndexWriter("writer").build();
final CreateTableRequest createPackage = new CreateTableRequest(sequenceNumber, "test", ssTableConfiguration);
final byte[] encodedVersion = networkPackageToByte(createPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final CreateTableRequest decodedPackage = CreateTableRequest.decodeTuple(bb);
Assert.assertEquals(createPackage.getTable(), decodedPackage.getTable());
Assert.assertEquals(createPackage.getTupleStoreConfiguration(), ssTableConfiguration);
Assert.assertEquals(createPackage, decodedPackage);
Assert.assertEquals(createPackage.hashCode(), decodedPackage.hashCode());
Assert.assertEquals(createPackage.toString(), decodedPackage.toString());
}
use of org.bboxdb.network.packages.request.CreateTableRequest in project bboxdb by jnidzwetzki.
the class CreateTableHandler method handleRequest.
@Override
public /**
* Handle the create table call
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final CreateTableRequest createPackage = CreateTableRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = createPackage.getTable();
logger.info("Got create call for table: {}", requestTable.getFullname());
final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
if (tupleStoreAdapter.isTableKnown(requestTable)) {
logger.warn("Table name is already known {}", requestTable.getFullname());
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_TABLE_EXISTS);
clientConnectionHandler.writeResultPackage(responsePackage);
} else {
tupleStoreAdapter.writeTuplestoreConfiguration(requestTable, createPackage.getTupleStoreConfiguration());
clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
}
} catch (Exception e) {
logger.warn("Error while delete tuple", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
Aggregations