-
Notifications
You must be signed in to change notification settings - Fork 8
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 #206 from eclipse-passage/560445
Bug 560445 - [YARS] support incremental monitoring
- Loading branch information
Showing
11 changed files
with
192 additions
and
32 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
74 changes: 74 additions & 0 deletions
74
...yars.api.tests/src/org/eclipse/passage/loc/yars/internal/api/export/CountingProgress.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,74 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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.loc.yars.internal.api.export; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.passage.loc.yars.internal.api.Progress; | ||
import org.eclipse.passage.loc.yars.internal.api.model.InMemoryStorage; | ||
|
||
@SuppressWarnings("restriction") | ||
final class CountingProgress implements Progress<ExportEntry> { | ||
|
||
private final InMemoryStorage storage; | ||
private final int limit; | ||
private int estimated = 0; | ||
private int started = 0; | ||
private int finished = 0; | ||
private List<String> infos = new ArrayList<>(); | ||
|
||
CountingProgress(InMemoryStorage storage, int limit) { | ||
this.storage = storage; | ||
this.limit = limit; | ||
} | ||
|
||
@Override | ||
public void estimate(int amount) { | ||
estimated = amount; | ||
} | ||
|
||
@Override | ||
public void reportNodeSrart(ExportEntry entry) { | ||
started++; | ||
} | ||
|
||
@Override | ||
public void reportNodeFinish(ExportEntry entry) { | ||
finished++; | ||
} | ||
|
||
@Override | ||
public void report(String info) { | ||
this.infos.add(info); | ||
} | ||
|
||
@Override | ||
public boolean cancelDemanded() { | ||
return finished >= limit; | ||
} | ||
|
||
void assertContractIsOk() { | ||
assertTrue(started == finished); | ||
assertTrue(started <= estimated); | ||
} | ||
|
||
void assertStateIsOk() { | ||
assertEquals(storage.size(), estimated); | ||
assertTrue(started == limit); | ||
} | ||
|
||
} |
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
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
75 changes: 75 additions & 0 deletions
75
...loc.yars.api.tests/src/org/eclipse/passage/loc/yars/internal/api/export/ProgressTest.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,75 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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.loc.yars.internal.api.export; | ||
|
||
import java.util.ArrayList; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import org.eclipse.passage.loc.yars.internal.api.DefaultDosHandler; | ||
import org.eclipse.passage.loc.yars.internal.api.DosHandleMedia; | ||
import org.eclipse.passage.loc.yars.internal.api.FetchParams; | ||
import org.eclipse.passage.loc.yars.internal.api.ListMedia; | ||
import org.eclipse.passage.loc.yars.internal.api.Progress; | ||
import org.eclipse.passage.loc.yars.internal.api.SingleSwoopExport; | ||
import org.eclipse.passage.loc.yars.internal.api.model.InMemoryStorage; | ||
import org.eclipse.passage.loc.yars.internal.api.model.StoredEntry; | ||
import org.junit.Test; | ||
|
||
@SuppressWarnings("restriction") | ||
public final class ProgressTest { | ||
|
||
@Test | ||
public void ticks() { | ||
exportWithProgress(InMemoryStorage::size); | ||
} | ||
|
||
@Test | ||
public void cancells() { | ||
exportWithProgress(storage -> storage.size() / 3); | ||
} | ||
|
||
private void exportWithProgress(Function<InMemoryStorage, Integer> limit) { | ||
InMemoryStorage storage = storage(); | ||
CountingProgress progress = new CountingProgress(storage, limit.apply(storage)); | ||
queryResult(new Enlistment<ExportEntry>(new ArrayList<>()), progress); | ||
progress.assertContractIsOk(); | ||
progress.assertStateIsOk(); | ||
} | ||
|
||
private InMemoryStorage storage() { | ||
return new InMemoryStorage( // | ||
IntStream.range(1, 16) // | ||
.mapToObj(i -> new StoredEntry(Integer.toString(i), Integer.toBinaryString(i))) // | ||
.collect(Collectors.toList()) // | ||
); | ||
} | ||
|
||
private void queryResult(ListMedia<ExportEntry> media, Progress<ExportEntry> progress) { | ||
InMemoryStorage storage = new InMemoryStorage( // | ||
IntStream.range(1, 16) // | ||
.mapToObj(i -> new StoredEntry(Integer.toString(i), Integer.toBinaryString(i))) // | ||
.collect(Collectors.toList()) // | ||
); | ||
new SingleSwoopExport<InMemoryStorage, ExportEntry>(new All().fetch(// | ||
storage, // | ||
new FetchParams.Empty()))// | ||
.write(// | ||
new DosHandleMedia<ExportEntry>(// | ||
media, // | ||
new DefaultDosHandler()), // | ||
progress); | ||
} | ||
|
||
} |
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