-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from LikeTheSalad/disk-buffering-part-2
Adding disk buffering, part 2
- Loading branch information
Showing
7 changed files
with
196 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...a/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.internal.features.persistence; | ||
|
||
import io.opentelemetry.contrib.disk.buffering.internal.files.TemporaryFileProvider; | ||
import java.io.File; | ||
import java.util.UUID; | ||
|
||
/** | ||
* This class is internal and not for public use. Its APIs are unstable and can change at any time. | ||
*/ | ||
public final class SimpleTemporaryFileProvider implements TemporaryFileProvider { | ||
private final File tempDir; | ||
|
||
public SimpleTemporaryFileProvider(File tempDir) { | ||
this.tempDir = tempDir; | ||
} | ||
|
||
/** Creates a unique file instance using the provided prefix and the current time in millis. */ | ||
@Override | ||
public File createTemporaryFile(String prefix) { | ||
return new File(tempDir, prefix + "_" + UUID.randomUUID() + ".tmp"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.internal.features.persistence; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
class SimpleTemporaryFileProviderTest { | ||
@TempDir File tempDir; | ||
|
||
@Test | ||
void createUniqueFilesBasedOnCurrentTimeAndPrefix() throws InterruptedException { | ||
SimpleTemporaryFileProvider provider = new SimpleTemporaryFileProvider(tempDir); | ||
File first = provider.createTemporaryFile("a"); | ||
File second = provider.createTemporaryFile("b"); | ||
Thread.sleep(1); | ||
File third = provider.createTemporaryFile("a"); | ||
|
||
assertThat(first.getName()).startsWith("a").endsWith(".tmp"); | ||
assertThat(second.getName()).startsWith("b").endsWith(".tmp"); | ||
assertThat(third.getName()).startsWith("a").endsWith(".tmp"); | ||
assertThat(first).isNotEqualTo(third); | ||
|
||
assertThat(first.getParentFile()).isEqualTo(tempDir); | ||
assertThat(second.getParentFile()).isEqualTo(tempDir); | ||
assertThat(third.getParentFile()).isEqualTo(tempDir); | ||
} | ||
} |