Skip to content

Commit

Permalink
Move more usage to guarded model. Document python test entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
devinrsmith committed Jan 16, 2024
1 parent 1f4480e commit 4ac96ef
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@

import io.deephaven.time.calendar.BusinessCalendar;
import io.deephaven.time.calendar.Calendars;
import io.deephaven.util.annotations.ScriptApi;

public final class CalendarsHelper {

/**
* This invokes {@link Calendars#addCalendar(BusinessCalendar)} for all the
* {@link Calendars#calendarsFromConfiguration()}.
*/
@ScriptApi
public static void addCalendarsFromConfiguration() {
for (BusinessCalendar calendar : Calendars.calendarsFromConfiguration()) {
Calendars.addCalendar(calendar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@

final class CalendarInit {

static {
for (BusinessCalendar calendar : Calendars.calendarsFromConfiguration()) {
Calendars.addCalendar(calendar);
}
}

static void noop() {
private static volatile boolean initialized = false;

/**
* This is a guarded initialization of {@link Calendars#addCalendar(BusinessCalendar)} for all the
* {@link Calendars#calendarsFromConfiguration()}.
*/
static void init() {
if (!initialized) {
synchronized (CalendarInit.class) {
if (!initialized) {
for (BusinessCalendar calendar : Calendars.calendarsFromConfiguration()) {
Calendars.addCalendar(calendar);
}
initialized = true;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

public class TestCalendars extends BaseArrayTestCase {

static {
CalendarInit.noop();
@Override
public void setUp() throws Exception {
super.setUp();
CalendarInit.init();
}

public void testDefault() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
* See also {@code StaticCalendarMethodsGenerator}.
*/
public class TestStaticCalendarMethods extends BaseArrayTestCase {

static {
CalendarInit.noop();
}

private final Map<Class<?>, Object[]> data = new HashMap<>();

{
Expand Down Expand Up @@ -97,6 +92,12 @@ private void executeTest(final Method m1, final Method m2)
}
}

@Override
public void setUp() throws Exception {
super.setUp();
CalendarInit.init();
}

// test to make sure these methods work inside the query strings
public void testAll() {
final Set<String> excludes = new HashSet<>();
Expand Down

0 comments on commit 4ac96ef

Please sign in to comment.