Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
tangyoupeng committed Dec 13, 2024
1 parent b3d9d1e commit 4cf9b0a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion sdk/java/src/main/java/io/juicefs/JuiceFileSystemImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ public void initialize(URI uri, Configuration conf) throws IOException {
throw new IOException("JuiceFS initialized failed for jfs://" + name);
}
boolean asBgTask = conf.getBoolean("juicefs.internal-bg-task", false);
if (!asBgTask) {
if (asBgTask) {
LOG.debug("background fs {}|({})", name, handle);
} else {
BgTaskUtil.register(name, handle);
}
homeDirPrefix = conf.get("dfs.user.home.dir.prefix", "/user");
Expand Down
4 changes: 3 additions & 1 deletion sdk/java/src/main/java/io/juicefs/utils/BgTaskUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public static void register(String volName, long handle) {
synchronized (runningInstance) {
LOG.debug("register instance for {}({})", volName, handle);
if (!runningInstance.containsKey(volName)) {
runningInstance.put(volName, new HashSet<>());
Set<Long> handles = new HashSet<>();
handles.add(handle);
runningInstance.put(volName, handles);
} else {
runningInstance.get(volName).add(handle);
}
Expand Down
11 changes: 8 additions & 3 deletions sdk/java/src/test/java/io/juicefs/JuiceFileSystemBgTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.util.Map;
Expand All @@ -14,6 +16,8 @@
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY;

public class JuiceFileSystemBgTaskTest extends TestCase {
private static final Logger LOG = LoggerFactory.getLogger(JuiceFileSystemBgTaskTest.class);

public void testJuiceFileSystemBgTask() throws Exception {
FileSystem.closeAll();
Configuration conf = new Configuration();
Expand All @@ -31,13 +35,14 @@ public void testJuiceFileSystemBgTask() throws Exception {
pool.submit(() -> {
try (JuiceFileSystem jfs = new JuiceFileSystem()) {
jfs.initialize(URI.create("jfs://dev/"), conf);
if (ThreadLocalRandom.current().nextInt(10)%2==0) {
if (ThreadLocalRandom.current().nextInt(10) % 2 == 0) {
jfs.getFileBlockLocations(jfs.getFileStatus(new Path("jfs://dev/users")), 0, 1000);
}
} catch (Exception e) {
fail("unexpected exception");
LOG.error("unexpected exception", e);
} finally {
latch.countDown();
}
latch.countDown();
});
}
latch.await();
Expand Down
6 changes: 3 additions & 3 deletions sdk/java/src/test/java/io/juicefs/JuiceFileSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.common.collect.Lists;
import io.juicefs.utils.AclTransformation;
import io.juicefs.utils.BgTaskUtil;
import junit.framework.TestCase;
import org.apache.commons.io.IOUtils;
import org.apache.flink.runtime.fs.hdfs.HadoopRecoverableWriter;
Expand All @@ -38,7 +37,9 @@
import java.nio.ByteBuffer;
import java.security.PrivilegedExceptionAction;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

Expand All @@ -48,7 +49,6 @@
import static org.apache.hadoop.fs.permission.AclEntryScope.DEFAULT;
import static org.apache.hadoop.fs.permission.AclEntryType.*;
import static org.apache.hadoop.fs.permission.FsAction.*;
import static org.apache.hadoop.fs.permission.FsAction.ALL;
import static org.junit.Assert.assertArrayEquals;

public class JuiceFileSystemTest extends TestCase {
Expand Down

0 comments on commit 4cf9b0a

Please sign in to comment.