From e10096e6641def85e022ef2ea79f5104a0f28a37 Mon Sep 17 00:00:00 2001
From: eparovyshnaya
Date: Fri, 5 Apr 2024 18:44:02 +0300
Subject: [PATCH] [#1337] remove unused code
remove 'observatory' api, implementation and tests
---
.../META-INF/MANIFEST.MF | 3 +-
.../lic/internal/api/observatory/Limited.java | 47 -------
.../internal/api/observatory/Observatory.java | 58 --------
.../META-INF/MANIFEST.MF | 1 -
.../base/observatory/BaseObservatory.java | 112 ---------------
.../base/observatory/CheckSchedule.java | 82 -----------
.../internal/base/observatory/Expired.java | 59 --------
.../lic/internal/base/observatory/Guard.java | 60 --------
.../lic/internal/base/observatory/Pool.java | 45 ------
.../observatory/CheckScheduleTest.java | 40 ------
.../permission/observatory/Countdown.java | 38 -----
.../permission/observatory/Disaster.java | 26 ----
.../observatory/ObservatoryTest.java | 132 ------------------
.../permission/observatory/TimeLimited.java | 51 -------
.../tests/permission/observatory/Trouble.java | 26 ----
15 files changed, 1 insertion(+), 779 deletions(-)
delete mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/observatory/Limited.java
delete mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/observatory/Observatory.java
delete mode 100644 bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/BaseObservatory.java
delete mode 100644 bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/CheckSchedule.java
delete mode 100644 bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Expired.java
delete mode 100644 bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Guard.java
delete mode 100644 bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Pool.java
delete mode 100644 tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/CheckScheduleTest.java
delete mode 100644 tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Countdown.java
delete mode 100644 tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Disaster.java
delete mode 100644 tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/ObservatoryTest.java
delete mode 100644 tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/TimeLimited.java
delete mode 100644 tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Trouble.java
diff --git a/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF
index 92eac916e..f6dffe71c 100644
--- a/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF
@@ -24,5 +24,4 @@ Export-Package: org.eclipse.passage.lic.api,
org.eclipse.passage.lic.api.registry,
org.eclipse.passage.lic.api.requirements,
org.eclipse.passage.lic.api.restrictions,
- org.eclipse.passage.lic.api.version,
- org.eclipse.passage.lic.internal.api.observatory;x-friends:="org.eclipse.passage.lic.base"
+ org.eclipse.passage.lic.api.version
diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/observatory/Limited.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/observatory/Limited.java
deleted file mode 100644
index e71394411..000000000
--- a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/observatory/Limited.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.api.observatory;
-
-/**
- *
- * Describes the entry that can expire after some conditions in the outer world
- * are met.
- *
- *
- * Say, {@code BottleOfMilk} can easily implement the interface
- *
- *
- *
- * <{@code
- * public final class BottleOfMilk implements Limited {
- *
- * private final ZonedDateTime expirationDate;
- *
- * public BottleOfMilk(ZonedDateTime expirationDate) {
- * this.expirationDate = expirationDate;
- * }
- *
- * @Override
- * public boolean expired() {
- * return ZonedDateTime.now().isBefore(expirationDate);
- * }
- *
- * }
- * }
- *
- */
-public interface Limited {
-
- boolean expired();
-
-}
diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/observatory/Observatory.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/observatory/Observatory.java
deleted file mode 100644
index f7bfb46f4..000000000
--- a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/observatory/Observatory.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.api.observatory;
-
-/**
- *
- * This observatory keeps an eye on any captured entry, that can say in a moment
- * of time whether it is expired already or not yet.
- *
- *
- *
- * Ones in a period of time the observatory checks all watched entries if they
- * are expired already. And for the ones who do, a configured action is called.
- * Since this moment an expired entry in not watched anymore.
- *
- *
- *
- * There is no check on an observatory opening. The closest one takes place only
- * after a scheduled period of time is over.
- *
- *
- *
- * An entry can be put under the observatory control and removed from it
- * preliminary, prior this is done by TTL.
- *
- *
- *
- * To configure an observatory, you need only define
- *
- * - how often it will check expiration and
- * - what will it do for expired entries
- *
- *
- */
-public interface Observatory {
-
- /**
- * Put a {@link Limited} entry under the observatory control.
- */
- void watch(T limited);
-
- /**
- * Remove a {@link Limited} entry from the observatory control intentionally
- * prior it's expiration.
- */
- void forget(T limited);
-
-}
diff --git a/bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF
index 7c6854158..a13daebed 100644
--- a/bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF
@@ -27,7 +27,6 @@ Export-Package: org.eclipse.passage.lic.base,
org.eclipse.passage.lic.internal.base.access;x-internal:=true,
org.eclipse.passage.lic.internal.base.conditions;x-internal:=true,
org.eclipse.passage.lic.internal.base.inspection.hardware;x-friends:="org.eclipse.passage.loc.licenses.core,org.eclipse.passage.lic.oshi",
- org.eclipse.passage.lic.internal.base.observatory;x-internal:=true,
org.eclipse.passage.lic.internal.base.requirements;x-internal:=true,
org.eclipse.passage.lic.internal.base.time;x-friends:="org.eclipse.passage.lic.base.tests"
Import-Package: org.slf4j;version="1.7.36"
diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/BaseObservatory.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/BaseObservatory.java
deleted file mode 100644
index f4ac26667..000000000
--- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/BaseObservatory.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.base.observatory;
-
-import java.util.Set;
-import java.util.function.Consumer;
-
-import org.eclipse.passage.lic.internal.api.observatory.Limited;
-import org.eclipse.passage.lic.internal.api.observatory.Observatory;
-
-/**
- *
- * This observatory keeps an eye on any captured entry, that can say in a moment
- * of time whether it is expired already or not yet.
- *
- *
- *
- * Ones in a period of time the observatory checks all watched entries if they
- * are expired already. And for the ones who do, a configured action is called.
- * Since this moment an expired entry in not watched anymore.
- *
- *
- *
- * There is no check on an observatory opening. The closest one takes place only
- * after a scheduled period of time is over.
- *
- *
- *
- * An entry can be put under the observatory control and removed from it
- * preliminary, prior this is done by TTL.
- *
- *
- *
- * To configure an observatory, you need only define
- *
- * - how often it will check expiration and
- * - what will it do for expired entries
- *
- *
- *
- * @since 0.6
- */
-public final class BaseObservatory implements Observatory {
-
- private final Pool pool;
- private final Guard guard;
-
- /**
- *
- * When the time comes and an entry expires, {@code farewell} action is called
- * for it.
- *
- *
- *
- * The observatory does the brushing checks each {@code schedule} seconds, so an
- * entry cannot be processed precisely in a moment it expires, but some time
- * like {@code schedule} seconds after.
- *
- *
- * @param schedule period (in seconds) between checks
- * @param farewell handler to be notified of expired entries. Is not intended to
- * work long. Never bothered for naught: never gets {@code null}
- * or empty set.
- * @since 0.6
- */
- public BaseObservatory(CheckSchedule schedule, Consumer> farewell) {
- pool = new Pool();
- guard = new Guard(schedule, pool, farewell);
- }
-
- /**
- * The observatory can accept entries to watch and dismiss them after, but
- * checks start only after it is open.
- *
- * @since 0.6
- */
- public void open() {
- new Thread(guard).start();
- }
-
- /**
- * Put a {@link Limited} entry under the observatory control.
- *
- * @since 0.6
- */
- @Override
- public void watch(T limited) {
- pool.watch(limited);
- }
-
- /**
- * Remove a {@link Limited} entry from the observatory control intentionally
- * prior it's expiration.
- *
- * @since 0.6
- */
- @Override
- public void forget(T limited) {
- pool.forget(limited);
- }
-
-}
diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/CheckSchedule.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/CheckSchedule.java
deleted file mode 100644
index 204d571a0..000000000
--- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/CheckSchedule.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.base.observatory;
-
-import java.time.temporal.ChronoUnit;
-
-/**
- *
- * Schedule for observatory checks.
- *
- *
- *
- * Been defined for 5 minutes, causes the observatory to check for new
- * expired entries each 5 minutes (or so).
- *
- *
- * @since 0.6
- */
-public class CheckSchedule {
-
- private final int amount;
- private final ChronoUnit unit;
-
- /**
- *
- * Use desired units to define the most suitable check schedule.
- *
- *
- *
- * For example, {@code new CheckSchedule(2, ChronoUnit.DAYS)}, been given to an
- * observatory, will cause the closest expiration check to happen only in two
- * days since the observatory opening.
- *
- *
- * @param amount number of units
- * @unit {@linkplain ChronoUnit} constant to measure {@code amount}
- * @since 0.6
- */
- public CheckSchedule(int amount, ChronoUnit unit) {
- this.amount = amount;
- this.unit = unit;
- }
-
- /**
- * Default schedules are measured in minutes.
- *
- * @param minutes number of minutes
- * @since 0.6
- */
- public CheckSchedule(int minutes) {
- this(minutes, ChronoUnit.MINUTES);
- }
-
- /**
- * Default schedule is 10 minutes.
- *
- * @since 0.6
- */
- public CheckSchedule() {
- this(10, ChronoUnit.MINUTES);
- }
-
- /**
- * Reports the scheduled period duration in seconds.
- *
- * @since 0.6
- */
- public long seconds() {
- return unit.getDuration().getSeconds() * amount;
- }
-
-}
diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Expired.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Expired.java
deleted file mode 100644
index fab49ac6c..000000000
--- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Expired.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.base.observatory;
-
-import java.util.Set;
-import java.util.function.Consumer;
-
-import org.eclipse.passage.lic.internal.api.observatory.Limited;
-
-/**
- *
- * Set of {@link Limited}s, that have been found expired on a check.
- *
- *
- * Expired {@link Limited}s need to be disposed - it's the last care we
- * can do for those, who have run out of time on the Earth.
- *
- *
- * @see #dispose
- */
-final class Expired {
-
- private final Set origin;
-
- Expired(Set origin) {
- this.origin = origin;
- }
-
- /**
- *
- * The last attention an observatory pays to expired entries is a
- * disposal.
- *
- *
- * Here all expired {@link Limited}s are passed to the {@code farewell} action
- * in one fell swoop.
- *
- *
- * @param farewell should be a fast-running action. Never gets {@code null} or
- * empty set of entries.
- */
- void dispose(Consumer> farewell) {
- if (origin.isEmpty()) {
- return;
- }
- farewell.accept(origin);
- }
-
-}
diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Guard.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Guard.java
deleted file mode 100644
index 9c3aaab88..000000000
--- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Guard.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.base.observatory;
-
-import java.util.Set;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-import java.util.function.Consumer;
-
-import org.eclipse.passage.lic.internal.api.observatory.Limited;
-
-final class Guard implements Runnable {
-
- private final long period;
- private final Pool pool;
- private final Consumer> onExpire;
- private final Executor executor;
-
- /**
- * @param onExpire never gets {@code null} or empty set. The callback is
- * expected to complete shortly.
- */
- Guard(CheckSchedule schedule, Pool pool, Consumer> onExpire) {
- this.period = schedule.seconds();
- this.pool = pool;
- this.onExpire = onExpire;
- executor = Executors.newSingleThreadExecutor();
- }
-
- @Override
- public void run() {
- while (true) {
- rest();
- check();
- }
- }
-
- private void check() {
- executor.execute(() -> pool.popExpired().dispose(onExpire));
- }
-
- private void rest() {
- try {
- Thread.sleep(period * 1000);
- } catch (InterruptedException e) {
- // do nothing, just start new check ahead the schedule
- }
- }
-
-}
diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Pool.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Pool.java
deleted file mode 100644
index d3a9c9563..000000000
--- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/observatory/Pool.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.base.observatory;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.eclipse.passage.lic.internal.api.observatory.Limited;
-
-final class Pool {
- private final Set watched = new HashSet<>();
-
- void watch(T target) {
- synchronized (watched) {
- watched.add(target);
- }
- }
-
- void forget(T target) {
- synchronized (watched) {
- watched.remove(target);
- }
- }
-
- Expired popExpired() {
- synchronized (watched) {
- Set expired = watched.stream() //
- .filter(Limited::expired)//
- .collect(Collectors.toSet());
- watched.removeAll(expired);
- return new Expired(expired);
- }
- }
-}
diff --git a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/CheckScheduleTest.java b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/CheckScheduleTest.java
deleted file mode 100644
index 96c519c1c..000000000
--- a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/CheckScheduleTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.base.tests.permission.observatory;
-
-import static org.junit.Assert.assertEquals;
-
-import java.time.temporal.ChronoUnit;
-
-import org.eclipse.passage.lic.internal.base.observatory.CheckSchedule;
-import org.junit.Test;
-
-@SuppressWarnings("restriction")
-public class CheckScheduleTest {
-
- @Test
- public void testDefaultSchedule() {
- assertEquals(10 * 60, new CheckSchedule().seconds());
- }
-
- @Test
- public void testMinutesSchedule() {
- assertEquals(5 * 60, new CheckSchedule(5).seconds());
- }
-
- @Test
- public void testAlternativechedule() {
- assertEquals(3 * 24 * 60 * 60, new CheckSchedule(3, ChronoUnit.DAYS).seconds());
- }
-
-}
diff --git a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Countdown.java b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Countdown.java
deleted file mode 100644
index a3e8aa160..000000000
--- a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Countdown.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.base.tests.permission.observatory;
-
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.Consumer;
-
-import org.eclipse.passage.lic.internal.api.observatory.Limited;
-
-@SuppressWarnings("restriction")
-final class Countdown implements Consumer> {
- private final AtomicInteger counter;
-
- Countdown(int from) {
- this.counter = new AtomicInteger(from);
- }
-
- @Override
- public void accept(Set entries) {
- counter.updateAndGet(i -> i - entries.size());
- }
-
- boolean complete() {
- return counter.get() == 0;
- }
-
-}
diff --git a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Disaster.java b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Disaster.java
deleted file mode 100644
index 0aa1df846..000000000
--- a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Disaster.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.base.tests.permission.observatory;
-
-import java.util.Set;
-import java.util.function.Consumer;
-
-import org.eclipse.passage.lic.internal.api.observatory.Limited;
-
-@SuppressWarnings("restriction")
-final class Disaster implements Consumer> {
- @Override
- public void accept(Set entries) {
- throw new Error("Disaster is emulated for the entry expiration process"); //$NON-NLS-1$
- }
-}
diff --git a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/ObservatoryTest.java b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/ObservatoryTest.java
deleted file mode 100644
index 9a5d5dde9..000000000
--- a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/ObservatoryTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.base.tests.permission.observatory;
-
-import static org.junit.Assert.fail;
-
-import java.time.temporal.ChronoUnit;
-import java.util.Set;
-import java.util.function.Consumer;
-
-import org.eclipse.passage.lic.internal.api.observatory.Limited;
-import org.eclipse.passage.lic.internal.base.observatory.CheckSchedule;
-import org.eclipse.passage.lic.internal.base.observatory.BaseObservatory;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Test suite for {@linkplain BaseObservatory}, which mostly intended to keep an eye
- * on {@linkplain Limited} instances, given under it's watch and fire
- * {@code expired} action when a {@linkplain Limited} expires.
- *
- * @since 0.6
- */
-@SuppressWarnings("restriction")
-public class ObservatoryTest {
-
- /**
- *
- * This a two seconds test.
- *
- * Observatory is opened and the guard is scheduled to check it through every 1
- * second.
- *
- * - 0: put two {@code Limited}s under the observatory's watch, each valid for
- * 1 seconds
- * - 0.5: in a half a second check nothing is released yet
- * - 2: in a 1.5 seconds more check both entries are released.
- *
- */
- @Test
- public void twoSeconds() {
- Countdown countdown = new Countdown(2);
- BaseObservatory observatory = new BaseObservatory(buzy(), countdown);
- observatory.open();
- observatory.watch(new TimeLimited(1));
- observatory.watch(new TimeLimited(1));
-
- waitABit(500);
- Assert.assertFalse(countdown.complete()); // not yet
-
- assertCountdownIsComplete(countdown, 700); // kinda now
- }
-
- @Test
- public void forget() {
- Countdown countdown = new Countdown(1); // watch two entries, but then forget one of them
- BaseObservatory observatory = new BaseObservatory(buzy(), countdown);
- observatory.open();
- observatory.watch(new TimeLimited(1));
- TimeLimited toBeForgotten = new TimeLimited(1);
- observatory.watch(toBeForgotten);
-
- waitABit(500);
- Assert.assertFalse(countdown.complete());
-
- observatory.forget(toBeForgotten);
- assertCountdownIsComplete(countdown, 700);
- }
-
- @Test
-
- public void guardIsReliable() {
- testGuardReliability(new Trouble());
- }
-
- @Test
- public void guardIsHighlyReliable() {
- testGuardReliability(new Disaster());
- }
-
- private void testGuardReliability(Consumer> sabotage) {
- Countdown countdown = new Countdown(4);
- BaseObservatory observatory = new BaseObservatory(buzy(), countdown.andThen(sabotage));
- observatory.open();
- observatory.watch(new TimeLimited(1));
- observatory.watch(new TimeLimited(1));
-
- waitABit(1500);
- observatory.watch(new TimeLimited(1));
- waitABit(100);
- observatory.watch(new TimeLimited(1));
-
- assertCountdownIsComplete(countdown, 1200);
- }
-
- private void waitABit(int millis) {
- try {
- Thread.sleep(millis);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- private void assertCountdownIsComplete(Countdown countdown, int delay) {
- waitABit(delay);
- for (int i = 0; i < 5; i++) {
- if (countdown.complete())
- return;
- waitABit(500);
- }
- if (countdown.complete())
- fail("Some expired Limited are still active."); //$NON-NLS-1$
- }
-
- private CheckSchedule buzy() {
- return new CheckSchedule(1, ChronoUnit.SECONDS);
- }
- // multithreaded usage
- // failing in Limited::expire implementation
- // negative schedule
-
-}
diff --git a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/TimeLimited.java b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/TimeLimited.java
deleted file mode 100644
index e61f7b48d..000000000
--- a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/TimeLimited.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.base.tests.permission.observatory;
-
-import java.time.ZonedDateTime;
-import java.time.temporal.ChronoUnit;
-
-import org.eclipse.passage.lic.internal.api.observatory.Limited;
-
-@SuppressWarnings("restriction")
-final class TimeLimited implements Limited {
- private final String id;
- private final ZonedDateTime start;
- private final ZonedDateTime end;
-
- TimeLimited(ZonedDateTime start, ZonedDateTime end) {
- id = "L:" + Long.toHexString(System.currentTimeMillis()); //$NON-NLS-1$
- this.start = start;
- this.end = end;
- }
-
- TimeLimited(int endDelta) {
- this(ZonedDateTime.now(), ZonedDateTime.now().plus(endDelta, ChronoUnit.SECONDS));
- }
-
- TimeLimited() {
- this(3);
- }
-
- @Override
- public boolean expired() {
- ZonedDateTime now = ZonedDateTime.now();
- return now.isBefore(start) || now.isAfter(end);
- }
-
- @Override
- public String toString() {
- return String.format("%s (expired: %b)", id, expired()); //$NON-NLS-1$
- }
-
-}
diff --git a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Trouble.java b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Trouble.java
deleted file mode 100644
index a38a9b1fa..000000000
--- a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/permission/observatory/Trouble.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019, 2020 ArSysOp
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * https://www.eclipse.org/legal/epl-2.0/.
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * ArSysOp - initial API and implementation
- *******************************************************************************/
-package org.eclipse.passage.lic.internal.base.tests.permission.observatory;
-
-import java.util.Set;
-import java.util.function.Consumer;
-
-import org.eclipse.passage.lic.internal.api.observatory.Limited;
-
-@SuppressWarnings("restriction")
-final class Trouble implements Consumer> {
- @Override
- public void accept(Set entries) {
- throw new RuntimeException("Trouble is emulated for the entry expiration process"); //$NON-NLS-1$
- }
-}