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

Truetime.now issue #340

Merged
merged 3 commits into from
Jul 24, 2024
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
2 changes: 1 addition & 1 deletion android-plugin/metadata/notice.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dependencies.hash=6AB0841BC9D2A49600D8C01CB49722DD
dependencies.hash=DE88CF9A9513ADACB700200CCAF64110
2 changes: 1 addition & 1 deletion android-sdk-ktx/metadata/notice.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dependencies.hash=4335DC6BB998D19BBBD590A9B2803A50
dependencies.hash=3E9E21CD8D354DEE5A74726273DC2F2D
2 changes: 1 addition & 1 deletion android-sdk/metadata/notice.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dependencies.hash=A0177AAB7C169836786E530C6453B8A1
dependencies.hash=116B097450368CFACC99BF27198E0C94
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ public ElasticClock(TrueTimeWrapper trueTimeWrapper) {
public long now() {
if (trueTimeWrapper.isInitialized()) {
Elog.getLogger().debug("Returning true time");
return TimeUnit.MILLISECONDS.toNanos(trueTimeWrapper.now().getTime());
try {
return TimeUnit.MILLISECONDS.toNanos(trueTimeWrapper.now().getTime());
} catch (Throwable t) {
trueTimeWrapper.clearCachedInfo();
Elog.getLogger().error("Could not get true time", t);
}
}
Elog.getLogger().debug("Returning system time");
return TimeUnit.MILLISECONDS.toNanos(systemTimeProvider.getCurrentTimeMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;

import org.junit.Before;
Expand All @@ -31,9 +32,9 @@
import java.util.Date;
import java.util.concurrent.TimeUnit;

import co.elastic.apm.android.sdk.internal.opentelemetry.tools.ElasticClock;
import co.elastic.apm.android.sdk.internal.time.SystemTimeProvider;
import co.elastic.apm.android.sdk.internal.time.ntp.TrueTimeWrapper;
import co.elastic.apm.android.sdk.internal.opentelemetry.tools.ElasticClock;
import co.elastic.apm.android.sdk.testutils.BaseTest;

@RunWith(MockitoJUnitRunner.class)
Expand Down Expand Up @@ -61,7 +62,7 @@ public void whenProvidingNanoTime_returnSystemNanoTime() {
}

@Test
public void whenProvidingNow_withNoTrueTimeAvailable_returnSystemCurrentTimeInNanos() {
public void whenProvidingNow_withTrueTimeNotInitialized_returnSystemCurrentTimeInNanos() {
long systemTimeMillis = 12345;
long systemTimeNanos = TimeUnit.MILLISECONDS.toNanos(systemTimeMillis);
doReturn(systemTimeMillis).when(systemTimeProvider).getCurrentTimeMillis();
Expand All @@ -70,6 +71,17 @@ public void whenProvidingNow_withNoTrueTimeAvailable_returnSystemCurrentTimeInNa
assertEquals(systemTimeNanos, elasticClock.now());
}

@Test
public void whenProvidingNow_withNoTrueTimeAvailable_returnSystemCurrentTimeInNanos() {
long systemTimeMillis = 12345;
long systemTimeNanos = TimeUnit.MILLISECONDS.toNanos(systemTimeMillis);
doReturn(systemTimeMillis).when(systemTimeProvider).getCurrentTimeMillis();
doReturn(true).when(trueTimeWrapper).isInitialized();
doThrow(IllegalStateException.class).when(trueTimeWrapper).now();

assertEquals(systemTimeNanos, elasticClock.now());
}

@Test
public void whenProvidingNow_withTrueTimeAvailable_returnTrueTimeInNanos() {
long trueTimeMillis = 12345;
Expand Down
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[versions]
opentelemetry-android = "0.5.0-alpha"
opentelemetry = "1.37.0"
opentelemetry-alpha = "1.37.0-alpha"
opentelemetry-semconv = "1.25.0-alpha"
opentelemetry-contrib = "1.35.0-alpha"
opentelemetry = "1.40.0"
opentelemetry-alpha = "1.40.0-alpha"
opentelemetry-semconv = "1.26.0-alpha"
opentelemetry-contrib = "1.37.0-alpha"
mockito = "4.11.0"
byteBuddy = "1.14.17"
byteBuddy = "1.14.18"
okhttp = "4.12.0"
kotlin = "1.9.22"
kotlin = "1.9.23"
google-autoService = "1.1.1"

[libraries]
Expand Down
4 changes: 2 additions & 2 deletions manual_licenses_map.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
net.bytebuddy:byte-buddy:1.14.17|apache_v2
net.bytebuddy:byte-buddy-gradle-plugin:1.14.17|apache_v2
net.bytebuddy:byte-buddy:1.14.18|apache_v2
net.bytebuddy:byte-buddy-gradle-plugin:1.14.18|apache_v2
org.slf4j:slf4j-api:2.0.0|mit
com.squareup.okhttp3:okhttp:3.11.0|apache_v2
com.github.instacart.truetime-android:library:3.5|apache_v2
Loading