use of org.apache.bookkeeper.clients.exceptions.StreamNotFoundException in project bookkeeper by apache.
the class StorageAdminClientTest method testStreamAPI.
@Test
public void testStreamAPI() throws Exception {
// Create a namespace
String nsName = testName.getMethodName() + "_ns";
NamespaceConfiguration colConf = NamespaceConfiguration.newBuilder().setDefaultStreamConf(DEFAULT_STREAM_CONF).build();
NamespaceProperties colProps = FutureUtils.result(adminClient.createNamespace(nsName, colConf));
assertEquals(nsName, colProps.getNamespaceName());
assertEquals(colConf.getDefaultStreamConf(), colProps.getDefaultStreamConf());
// Create a stream
String streamName = testName.getMethodName() + "_stream";
StreamConfiguration streamConf = StreamConfiguration.newBuilder(DEFAULT_STREAM_CONF).build();
StreamProperties streamProps = FutureUtils.result(adminClient.createStream(nsName, streamName, streamConf));
assertEquals(streamName, streamProps.getStreamName());
assertEquals(StreamConfiguration.newBuilder(streamConf).setBackendServiceUrl(defaultBackendUri.toString()).build(), streamProps.getStreamConf());
// create a duplicated stream
try {
FutureUtils.result(adminClient.createStream(nsName, streamName, streamConf));
fail("Should fail on creation if stream " + streamName + " already exists");
} catch (StreamExistsException cee) {
// expected
} catch (ClientException ce) {
// TODO: currently it throws InternalServerError for stream exists case
assertTrue(ce.getMessage().endsWith("code = " + StatusCode.INTERNAL_SERVER_ERROR));
}
String notFoundStreamName = testName.getMethodName() + "_notfound";
// get a not-found stream
try {
FutureUtils.result(adminClient.getStream(nsName, notFoundStreamName));
fail("Should fail on get if stream " + notFoundStreamName + " doesn't exist");
} catch (StreamNotFoundException cnfe) {
// expected
}
// delete a not-found stream
try {
FutureUtils.result(adminClient.deleteStream(nsName, notFoundStreamName));
fail("Should fail on delete if stream " + notFoundStreamName + " doesn't exist");
} catch (StreamNotFoundException cnfe) {
// expected
}
// get an existing stream
StreamProperties getStreamProps = FutureUtils.result(adminClient.getStream(nsName, streamName));
assertEquals(streamProps, getStreamProps);
// delete an existing stream
Boolean deleted = FutureUtils.result(adminClient.deleteStream(nsName, streamName));
assertTrue(deleted);
// the stream should not exist after deleted.
try {
FutureUtils.result(adminClient.getStream(nsName, streamName));
fail("Should fail on get if stream " + nsName + " doesn't exist");
} catch (StreamNotFoundException cnfe) {
// expected
}
}
use of org.apache.bookkeeper.clients.exceptions.StreamNotFoundException in project bookkeeper by apache.
the class TestProtocolInternalUtils method testCreateRootRangeException.
//
// Test Exceptions related utils
//
@Test
public void testCreateRootRangeException() {
String name = "test-create-root-range-exception";
// stream exists exception
Throwable cause1 = createRootRangeException(name, StatusCode.STREAM_EXISTS);
assertTrue(cause1 instanceof StreamExistsException);
StreamExistsException see = (StreamExistsException) cause1;
// stream not found
Throwable cause2 = createRootRangeException(name, StatusCode.STREAM_NOT_FOUND);
assertTrue(cause2 instanceof StreamNotFoundException);
StreamNotFoundException snfe = (StreamNotFoundException) cause2;
// invalid stream name
Throwable invalidStreamNameCause = createRootRangeException(name, StatusCode.INVALID_STREAM_NAME);
assertTrue(invalidStreamNameCause instanceof InvalidStreamNameException);
InvalidStreamNameException isne = (InvalidStreamNameException) invalidStreamNameCause;
// failure
Throwable cause3 = createRootRangeException(name, StatusCode.FAILURE);
ClientException se = (ClientException) cause3;
assertEquals("fail to access its root range : code = " + StatusCode.FAILURE, se.getMessage());
// namespace exists exception
Throwable cause5 = createRootRangeException(name, StatusCode.NAMESPACE_EXISTS);
assertTrue(cause5 instanceof NamespaceExistsException);
// namespace not-found exception
Throwable cause6 = createRootRangeException(name, StatusCode.NAMESPACE_NOT_FOUND);
assertTrue(cause6 instanceof NamespaceNotFoundException);
// invalid namespace name
Throwable cause7 = createRootRangeException(name, StatusCode.INVALID_NAMESPACE_NAME);
assertTrue(cause7 instanceof InvalidNamespaceNameException);
}
use of org.apache.bookkeeper.clients.exceptions.StreamNotFoundException in project bookkeeper by apache.
the class RootRangeClientImplTestBase method testCreateRootRangeException.
@Test
public void testCreateRootRangeException() {
String name = "test-create-root-range-exception";
// stream exists exception
Throwable cause1 = createRootRangeException(name, StatusCode.STREAM_EXISTS);
assertTrue(cause1 instanceof StreamExistsException);
StreamExistsException see = (StreamExistsException) cause1;
// stream not found
Throwable cause2 = createRootRangeException(name, StatusCode.STREAM_NOT_FOUND);
assertTrue(cause2 instanceof StreamNotFoundException);
StreamNotFoundException snfe = (StreamNotFoundException) cause2;
// failure
Throwable cause3 = createRootRangeException(name, StatusCode.FAILURE);
assertTrue(cause3 instanceof ClientException);
ClientException se = (ClientException) cause3;
assertEquals("fail to access its root range : code = " + StatusCode.FAILURE, se.getMessage());
// unexpected
Throwable cause4 = createRootRangeException(name, StatusCode.BAD_VERSION);
assertTrue(cause4 instanceof ClientException);
// namespace exists exception
Throwable cause5 = createRootRangeException(name, StatusCode.NAMESPACE_EXISTS);
assertTrue(cause5 instanceof NamespaceExistsException);
// namespace not-found exception
Throwable cause6 = createRootRangeException(name, StatusCode.NAMESPACE_NOT_FOUND);
assertTrue(cause6 instanceof NamespaceNotFoundException);
// invalid namespace name
Throwable cause7 = createRootRangeException(name, StatusCode.INVALID_NAMESPACE_NAME);
assertTrue(cause7 instanceof InvalidNamespaceNameException);
}
use of org.apache.bookkeeper.clients.exceptions.StreamNotFoundException in project incubator-pulsar by apache.
the class JavaInstanceRunnable method setupStateTable.
private void setupStateTable() throws Exception {
if (null == stateStorageServiceUrl) {
return;
}
String tableNs = String.format("%s_%s", instanceConfig.getFunctionConfig().getTenant(), instanceConfig.getFunctionConfig().getNamespace()).replace('-', '_');
String tableName = instanceConfig.getFunctionConfig().getName();
// TODO (sijie): use endpoint for now
StorageClientSettings settings = StorageClientSettings.newBuilder().addEndpoints(NetUtils.parseEndpoint(stateStorageServiceUrl)).clientName("function-" + tableNs + "/" + tableName).build();
// TODO (sijie): provide a better way to provision the state table for functions
try (StorageAdminClient storageAdminClient = StorageClientBuilder.newBuilder().withSettings(settings).buildAdmin()) {
try {
result(storageAdminClient.getStream(tableNs, tableName));
} catch (NamespaceNotFoundException nnfe) {
result(storageAdminClient.createNamespace(tableNs, NamespaceConfiguration.newBuilder().setDefaultStreamConf(DEFAULT_STREAM_CONF).build()));
result(storageAdminClient.createStream(tableNs, tableName, DEFAULT_STREAM_CONF));
} catch (StreamNotFoundException snfe) {
result(storageAdminClient.createStream(tableNs, tableName, DEFAULT_STREAM_CONF));
}
}
log.info("Starting state table for function {}", instanceConfig.getFunctionConfig().getName());
this.storageClient = StorageClientBuilder.newBuilder().withSettings(settings).withNamespace(tableNs).build();
this.stateTable = result(storageClient.openTable(tableName));
}
Aggregations