use of org.apache.distributedlog.exceptions.InvalidStreamNameException in project bookkeeper by apache.
the class TestBKDistributedLogNamespace method testInvalidStreamName.
@Test(timeout = 60000)
public void testInvalidStreamName() throws Exception {
assertFalse(DLUtils.isReservedStreamName("test"));
assertTrue(DLUtils.isReservedStreamName(".test"));
URI uri = createDLMURI("/" + runtime.getMethodName());
Namespace namespace = NamespaceBuilder.newBuilder().conf(conf).uri(uri).build();
try {
namespace.openLog(".test1");
fail("Should fail to create invalid stream .test");
} catch (InvalidStreamNameException isne) {
// expected
}
DistributedLogManager dlm = namespace.openLog("test1");
LogWriter writer = dlm.startLogSegmentNonPartitioned();
writer.write(DLMTestUtil.getLogRecordInstance(1));
writer.close();
dlm.close();
try {
namespace.openLog(".test2");
fail("Should fail to create invalid stream .test2");
} catch (InvalidStreamNameException isne) {
// expected
}
try {
namespace.openLog("/ test2");
fail("should fail to create invalid stream / test2");
} catch (InvalidStreamNameException isne) {
// expected
}
try {
char[] chars = new char[6];
for (int i = 0; i < chars.length; i++) {
chars[i] = 'a';
}
chars[0] = 0;
String streamName = new String(chars);
namespace.openLog(streamName);
fail("should fail to create invalid stream " + streamName);
} catch (InvalidStreamNameException isne) {
// expected
}
try {
char[] chars = new char[6];
for (int i = 0; i < chars.length; i++) {
chars[i] = 'a';
}
chars[3] = '\u0010';
String streamName = new String(chars);
namespace.openLog(streamName);
fail("should fail to create invalid stream " + streamName);
} catch (InvalidStreamNameException isne) {
// expected
}
DistributedLogManager newDLM = namespace.openLog("test_2-3");
LogWriter newWriter = newDLM.startLogSegmentNonPartitioned();
newWriter.write(DLMTestUtil.getLogRecordInstance(1));
newWriter.close();
newDLM.close();
Iterator<String> streamIter = namespace.getLogs();
Set<String> streamSet = Sets.newHashSet(streamIter);
assertEquals(2, streamSet.size());
assertTrue(streamSet.contains("test1"));
assertTrue(streamSet.contains("test_2-3"));
namespace.close();
}
use of org.apache.distributedlog.exceptions.InvalidStreamNameException in project bookkeeper by apache.
the class TestBKDistributedLogManager method testInvalidStreamFromInvalidZkPath.
@Test(timeout = 60000)
public void testInvalidStreamFromInvalidZkPath() throws Exception {
String baseName = testNames.getMethodName();
String streamName = "\0blah";
URI uri = createDLMURI("/" + baseName);
Namespace namespace = NamespaceBuilder.newBuilder().conf(conf).uri(uri).build();
DistributedLogManager dlm = null;
AsyncLogWriter writer = null;
try {
dlm = namespace.openLog(streamName);
writer = dlm.startAsyncLogSegmentNonPartitioned();
fail("should have thrown");
} catch (InvalidStreamNameException e) {
} finally {
if (null != writer) {
Utils.close(writer);
}
if (null != dlm) {
dlm.close();
}
namespace.close();
}
}
Aggregations