You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/03/29 08:32:04 UTC
[camel] branch master updated: Camel 13368 - LevelDB NPE if
fileName missing separator (#2845)
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 08769e0 Camel 13368 - LevelDB NPE if fileName missing separator (#2845)
08769e0 is described below
commit 08769e0e8ce78c0e855b4675781a9f9ca929a1e0
Author: Mikael Grevsten <mi...@gmail.com>
AuthorDate: Fri Mar 29 09:31:57 2019 +0100
Camel 13368 - LevelDB NPE if fileName missing separator (#2845)
* Fix using NIO utils instead
* Trying to adapt o checkstyle
Signed-off-by: Mikael Grevsten <mi...@tradechannel.se>
* Fixing header
Signed-off-by: Mikael Grevsten <mi...@tradechannel.se>
* Revert "Fixing header"
This reverts commit 377d110c
Signed-off-by: Mikael Grevsten <mi...@tradechannel.se>
* Fixing header
Signed-off-by: Mikael Grevsten <mi...@tradechannel.se>
* Fixing header again
Signed-off-by: Mikael Grevsten <mi...@tradechannel.se>
* Fix using NIO utils instead
# Conflicts:
# components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java
* Damn you headers
Signed-off-by: Mikael Grevsten <mi...@tradechannel.se>
* REmoving final again
Signed-off-by: Mikael Grevsten <mi...@tradechannel.se>
* Removing final again, damn you IDEA
Signed-off-by: Mikael Grevsten <mi...@tradechannel.se>
* Fixed checkstyle issues
Signed-off-by: Mikael Grevsten <mi...@tradechannel.se>
---
.../camel/component/leveldb/LevelDBFile.java | 25 +++++---
.../camel/component/leveldb/LevelDBSetupTest.java | 69 ++++++++++++++++++++++
2 files changed, 85 insertions(+), 9 deletions(-)
diff --git a/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java b/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java
index 78d78c1..1198a8b 100644
--- a/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java
+++ b/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java
@@ -18,7 +18,9 @@ package org.apache.camel.component.leveldb;
import java.io.File;
import java.io.IOException;
-
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import org.apache.camel.Service;
import org.apache.camel.util.IOHelper;
import org.iq80.leveldb.CompressionType;
@@ -29,6 +31,11 @@ import org.iq80.leveldb.WriteOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+
+import static org.fusesource.leveldbjni.JniDBFactory.factory;
+
+
/**
* Manages access to a shared <a href="https://github.com/fusesource/leveldbjni/">LevelDB</a> file.
* <p/>
@@ -55,22 +62,22 @@ public class LevelDBFile implements Service {
return db;
}
- public void setFile(File file) throws IOException {
- this.file = file;
- }
-
public File getFile() {
return file;
}
- public void setFileName(String fileName) {
- this.file = new File(fileName);
+ public void setFile(File file) throws IOException {
+ this.file = file;
}
public String getFileName() throws IOException {
return file.getCanonicalPath();
}
+ public void setFileName(String fileName) {
+ this.file = new File(fileName);
+ }
+
public int getWriteBufferSize() {
return writeBufferSize;
}
@@ -170,8 +177,8 @@ public class LevelDBFile implements Service {
options.createIfMissing(true);
try {
- getFile().getParentFile().mkdirs();
- DBFactory factory = getFactory();
+ final Path dbFile = Paths.get(this.getFileName());
+ Files.createDirectories(dbFile.getParent());
db = factory.open(getFile(), options);
} catch (IOException ioe) {
throw new RuntimeException("Error opening LevelDB with file " + getFile(), ioe);
diff --git a/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java b/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java
new file mode 100644
index 0000000..89ad023
--- /dev/null
+++ b/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.leveldb;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+
+/**
+ * The class LevelDBSetupTest
+ *
+ * @author mgr, 2019-03-27
+ * @version 1.0
+ */
+public class LevelDBSetupTest extends CamelTestSupport {
+ /**
+ * The Level db file.
+ */
+ private LevelDBFile levelDBFile;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test level db start with no path.
+ */
+ @Test
+ public void testLevelDBStartWithNoPath() {
+ deleteDirectory("leveldb.dat");
+ levelDBFile = new LevelDBFile();
+ levelDBFile.setFileName("leveldb.dat");
+ levelDBFile.start();
+ levelDBFile.stop();
+ }
+
+ /**
+ * Test level db start with path.
+ */
+ @Test
+ public void testLevelDBStartWithPath() {
+ deleteDirectory("target/data");
+ levelDBFile = new LevelDBFile();
+ levelDBFile.setFileName("target/data/leveldb.dat");
+ levelDBFile.start();
+ levelDBFile.stop();
+ }
+}