Skip to content

Commit

Permalink
feat: sdk storage check fix (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray authored Sep 27, 2023
1 parent 818195b commit e01ae5e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 27 deletions.
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");
}
}
}
}

0 comments on commit e01ae5e

Please sign in to comment.