Skip to content

Commit

Permalink
GitHub actions fixes apache#4
Browse files Browse the repository at this point in the history
  • Loading branch information
FilippoMuschera committed Jun 13, 2023
1 parent b1689c5 commit 3a406c0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.nio.file.Paths;
import java.util.*;
import java.util.function.Supplier;

import static org.apache.bookkeeper.bookie.BookieImplTest.generateIndexDirs;
Expand Down Expand Up @@ -270,12 +268,15 @@ private String[] generateTempDirs(int n, String suffix) throws IOException {
ledgerFiles = new File[n];
}
String[] ret = new String[n];
Random random = new Random();
for (int i = 0; i < n; i++) {
Path path = Files.createTempDirectory(suffix + i);
dirs.add(path.toFile());
ret[i] = path.toFile().getPath();
String dirPath = "./target/tempDirs/" + suffix + i + random.nextInt();
File directory = new File(dirPath);
directory.mkdir();
dirs.add(directory);
ret[i] = directory.getPath();
if (suffix.equals(LEDGER_STRING)) {
ledgerFiles[i] = path.toFile();
ledgerFiles[i] = directory;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
Expand All @@ -24,9 +25,11 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
Expand All @@ -39,7 +42,7 @@ public class BookieImplMockTest {


private static final List<File> dirs = new ArrayList<>();
private static BookieImpl bookie;
private static BookieImpl bookie = null;
private final String LEDGER_STRING = "ledger";
private final InputBundle bundle = InputBundle.getDefault();
ServerConfiguration conf = new ServerConfiguration();
Expand Down Expand Up @@ -95,20 +98,34 @@ public BookieImplMockTest() throws IOException {

private static File[] generateIndexDirs(int n) throws IOException {
File[] indexFiles = new File[n];
Random random = new Random();
for (int i = 0; i < n; i++) {
indexFiles[i] = Files.createTempDirectory("index" + i).toFile();
String dirPath = "./target/tempDirs/" + "index" + i + random.nextInt();
File directory = new File(dirPath);
directory.mkdir();
indexFiles[i] = directory;
dirs.add(indexFiles[i]);
}

return indexFiles;
}
@Before
public void before() {
if (bookie != null && bookie.isRunning()) {
bookie.shutdown();
assertFalse(bookie.isRunning());

}
}

@AfterClass
public static void afterClass() {

bookie.shutdown();
assertFalse(bookie.isRunning());
Mockito.clearAllCaches();
if (bookie != null && bookie.isRunning()) {
bookie.shutdown();
assertFalse(bookie.isRunning());

}

}

Expand Down Expand Up @@ -378,12 +395,15 @@ private String[] generateTempDirs(int n, String suffix) throws IOException {
ledgerFiles = new File[n];
}
String[] ret = new String[n];
Random random = new Random();
for (int i = 0; i < n; i++) {
Path path = Files.createTempDirectory(suffix + i);
dirs.add(path.toFile());
ret[i] = path.toFile().getPath();
String dirPath = "./target/tempDirs/" + suffix + i + random.nextInt();
File directory = new File(dirPath);
directory.mkdir();
dirs.add(directory);
ret[i] = directory.getPath();
if (suffix.equals(LEDGER_STRING)) {
ledgerFiles[i] = path.toFile();
ledgerFiles[i] = directory;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.bookkeeper.net.BookieId;
import org.apache.bookkeeper.stats.StatsLogger;
import org.apache.bookkeeper.util.DiskChecker;
import org.apache.bookkeeper.util.MathUtils;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.AfterClass;
Expand All @@ -27,10 +28,8 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -319,12 +318,15 @@ private String[] generateTempDirs(int n, String suffix) throws IOException {
ledgerFiles = new File[n];
}
String[] ret = new String[n];
Random random = new Random();
for (int i = 0; i < n; i++) {
Path path = Files.createTempDirectory(suffix + i);
dirs.add(path.toFile());
ret[i] = path.toFile().getPath();
String dirPath = "./target/tempDirs/" + suffix + i + random.nextInt();
File directory = new File(dirPath);
directory.mkdir();
dirs.add(directory);
ret[i] = directory.getPath();
if (suffix.equals(LEDGER_STRING)) {
ledgerFiles[i] = path.toFile();
ledgerFiles[i] = directory;
}
}

Expand Down

0 comments on commit 3a406c0

Please sign in to comment.