Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directory refactoring #79

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package ly.count.java.demo;

import ly.count.sdk.java.Config;
import ly.count.sdk.java.Countly;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.CountDownLatch;
import ly.count.sdk.java.Config;
import ly.count.sdk.java.Countly;

public class BackendModeExample {
final static String DEVICE_ID = "device-id";
Expand Down Expand Up @@ -314,8 +313,10 @@ public static void main(String[] args) throws Exception {
String[] sdkStorageRootPath = { System.getProperty("user.home"), "__COUNTLY", "java_test" };
File sdkStorageRootDirectory = new File(String.join(File.separator, sdkStorageRootPath));

if(sdkStorageRootDirectory.mkdirs()){
System.out.println("Directory creation failed");
if (!(sdkStorageRootDirectory.exists() && sdkStorageRootDirectory.isDirectory())) {
if (!sdkStorageRootDirectory.mkdirs()) {
System.out.println("Directory creation failed");
}
}

// Main initialization call, SDK can be used after this one is done
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package ly.count.java.demo;

import ly.count.sdk.java.Config;
import ly.count.sdk.java.Countly;
import ly.count.sdk.java.internal.Device;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import ly.count.sdk.java.Config;
import ly.count.sdk.java.Countly;
import ly.count.sdk.java.internal.Device;

public class BackendModePerformanceTests {
final static String DEVICE_ID = "device-id";
Expand All @@ -27,8 +26,10 @@ private static void initSDK(int eventQueueSize, int requestQueueSize) {
String[] sdkStorageRootPath = { System.getProperty("user.home"), "__COUNTLY", "java_test" };
File sdkStorageRootDirectory = new File(String.join(File.separator, sdkStorageRootPath));

if(sdkStorageRootDirectory.mkdirs()){
System.out.println("Directory creation failed");
if (!(sdkStorageRootDirectory.exists() && sdkStorageRootDirectory.isDirectory())) {
if (!sdkStorageRootDirectory.mkdirs()) {
System.out.println("Directory creation failed");
}
}

// Main initialization call, SDK can be used after this one is done
Expand Down
7 changes: 4 additions & 3 deletions app-java/src/main/java/ly/count/java/demo/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

import ly.count.sdk.java.Config;
import ly.count.sdk.java.Countly;
import ly.count.sdk.java.internal.LogCallback;
Expand Down Expand Up @@ -125,8 +124,10 @@ public static void main(String[] args) throws Exception {
String[] sdkStorageRootPath = { System.getProperty("user.home"), "__COUNTLY", "java_test" };
File sdkStorageRootDirectory = new File(String.join(File.separator, sdkStorageRootPath));

if(sdkStorageRootDirectory.mkdirs()){
System.out.println("Directory creation failed");
if (!(sdkStorageRootDirectory.exists() && sdkStorageRootDirectory.isDirectory())) {
if (!sdkStorageRootDirectory.mkdirs()) {
System.out.println("Directory creation failed");
}
}

Config config = new Config(COUNTLY_SERVER_URL, COUNTLY_APP_KEY, sdkStorageRootDirectory)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package ly.count.sdk.java.internal;

import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import ly.count.sdk.java.Config;
import ly.count.sdk.java.Countly;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.util.*;

@RunWith(JUnit4.class)
public class BackendModeTests {
private ModuleBackendMode moduleBackendMode;
Expand All @@ -25,12 +31,8 @@ public static void init() {
cc.setEventQueueSizeToSend(4).enableBackendMode();

// System specific folder structure
String[] sdkStorageRootPath = { System.getProperty("user.home"), "__COUNTLY", "java_test" };
File sdkStorageRootDirectory = new File(String.join(File.separator, sdkStorageRootPath));

if(sdkStorageRootDirectory.mkdirs()){
System.out.println("Directory creation failed");
}
File sdkStorageRootDirectory = TestUtils.getSdkStorageRootDirectory();
TestUtils.checkSdkStorageRootDirectoryExist(sdkStorageRootDirectory);

Countly.init(sdkStorageRootDirectory, cc);
}
Expand Down
14 changes: 14 additions & 0 deletions sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,18 @@ private static Map<String, String> parseRequestParams(File file) throws IOExcept
return paramMap;
}
}

static File getSdkStorageRootDirectory() {
// System specific folder structure
String[] sdkStorageRootPath = { System.getProperty("user.home"), "__COUNTLY", "java_test" };
return new File(String.join(File.separator, sdkStorageRootPath));
}

static void checkSdkStorageRootDirectoryExist(File directory) {
if (!(directory.exists() && directory.isDirectory())) {
if (!directory.mkdirs()) {
throw new RuntimeException("Directory creation failed");
}
}
}
}