use of com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl in project step by STEPBible.
the class LoaderTest method getLoader.
/**
* Gets a loader to be tested
*
* @param key the key to the properties
* @param file where the file that should be tested is
* @return the loader
*/
private Loader getLoader(final String key, final String file) {
final Properties coreProperties = new Properties();
coreProperties.put(key, file);
final JSwordVersificationService versificationService = TestUtils.mockVersificationService();
return new Loader(new JSwordPassageServiceImpl(versificationService, null, null, null, mock(VersionResolver.class), null), null, coreProperties, this.entityManager, this.clientSessionProvider, mock(AppManagerService.class));
}
use of com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl in project step by STEPBible.
the class SearchServiceImplTest method getSearchServiceUnderTest.
/**
* @return the search service to test
*/
private SearchServiceImpl getSearchServiceUnderTest() {
final JSwordMetadataService meta = mock(JSwordMetadataService.class);
final JSwordModuleService module = mock(JSwordModuleService.class);
final JSwordVersificationService versificationService = TestUtils.mockVersificationService();
final PassageOptionsValidationService optionsValidationService = mock(PassageOptionsValidationService.class);
final JSwordPassageServiceImpl jsword = new JSwordPassageServiceImpl(versificationService, null, null, null, TestUtils.mockVersionResolver(), optionsValidationService);
when(optionsValidationService.getAvailableFeaturesForVersion(any(String.class), any(List.class), any(String.class), any(InterlinearMode.class))).thenReturn(new AvailableFeatures());
when(module.isInstalled("ESV_th")).thenReturn(true);
when(module.isIndexed(any(String.class))).thenReturn(true);
when(meta.supportsFeature(any(String.class), any(LookupOption.class))).thenReturn(true);
final JSwordSearchServiceImpl jswordSearch = new JSwordSearchServiceImpl(versificationService, null, jsword);
subjects = new SubjectSearchServiceImpl(entityManager, jswordSearch, meta, module, versificationService);
return new SearchServiceImpl(jswordSearch, meta, versificationService, subjects, new TimelineServiceImpl(entityManager, jsword), null, entityManager, TestUtils.mockVersionResolver(), mock(LexiconDefinitionServiceImpl.class), null, null);
}
use of com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl in project step by STEPBible.
the class PerformancePassageRetrieval method testConcurrencyIssueThroughStep.
/**
* tries to replicate the issue with bookdata not being able to be read in a concurrent fashion
*
* @throws NoSuchKeyException a no such key exception
* @throws BookException a book exception
* @throws InterruptedException when the thread is interrupted
*/
public static void testConcurrencyIssueThroughStep() throws NoSuchKeyException, BookException, InterruptedException {
final String[] names = { "KJV", "ESV_th" };
final String[] ref = { "Rom.2", "John 7", "2Ki.2", "Rom.1;John 4;2Ki.2", "Acts 3:4-6" };
final ThreadMXBean thbean = ManagementFactory.getThreadMXBean();
thbean.setThreadContentionMonitoringEnabled(true);
final JSwordPassageServiceImpl jsi = new JSwordPassageServiceImpl(TestUtils.mockVersificationService(), null, null, null, TestUtils.mockVersionResolver(), null);
final Queue<Long> times = new ConcurrentLinkedQueue<Long>();
final AtomicLong iterations = new AtomicLong();
final Runnable r1 = new Runnable() {
@Override
public void run() {
for (int ii = 0; ii < 1000; ii++) {
final long l = System.currentTimeMillis();
jsi.getOsisText(names[ii % 2], ref[ii % 5]);
times.add(System.currentTimeMillis() - l);
iterations.incrementAndGet();
}
final ThreadInfo threadInfo = thbean.getThreadInfo(new long[] { Thread.currentThread().getId() }, true, true)[0];
System.err.println("Waited a total of " + threadInfo.getBlockedCount() + " times, resulting in " + threadInfo.getBlockedTime() + "ms wasted time");
}
};
int ii = 0;
final long start = System.currentTimeMillis();
final List<Thread> threads = new ArrayList<Thread>();
while (ii++ < 16) {
final Thread t1 = new Thread(r1);
t1.start();
threads.add(t1);
}
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(10000);
} catch (final InterruptedException e) {
e.printStackTrace();
}
System.out.println(iterations.get() + " iterations so far");
}
}
}).start();
for (final Thread t : threads) {
t.join();
}
final long total = System.currentTimeMillis() - start;
System.err.println(String.format("Executed: %d in %d ms, %f ms / iteration", iterations.get(), total, (double) total / (double) iterations.get()));
}
use of com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl in project step by STEPBible.
the class InterleavedOsisReader method main.
/**
* Just shows XML on the stdout
*
* @param args not used
* @throws Exception any kind of exception
*/
public static void main(final String[] args) throws Exception {
final String[] versions = new String[] { "OSMHB", "ESV_th" };
final String ref = "Mic.5";
final boolean unicodeBreakDown = false;
final boolean compare = true;
final InterlinearMode interlinearMode = InterlinearMode.INTERLEAVED;
boolean format = false;
final Format prettyFormat = format ? Format.getPrettyFormat() : Format.getRawFormat();
final Book currentBook = Books.installed().getBook(versions[0]);
final Book[] books = new Book[versions.length];
for (int ii = 0; ii < versions.length; ii++) {
books[ii] = Books.installed().getBook(versions[ii]);
}
final BookData bookData = new BookData(books, currentBook.getKey(ref), compare);
final Element osisFragment = bookData.getOsisFragment();
final XMLOutputter xmlOutputter = new XMLOutputter(prettyFormat);
final String inputString = xmlOutputter.outputString(osisFragment);
LOGGER.debug(inputString);
if (unicodeBreakDown) {
outputUnicode(inputString);
}
// do the test
final JSwordPassageServiceImpl jsi = new JSwordPassageServiceImpl(TestUtils.mockVersificationService(), null, null, null, TestUtils.mockVersionResolver(), null);
final List<LookupOption> options = new ArrayList<LookupOption>();
options.add(LookupOption.CHAPTER_BOOK_VERSE_NUMBER);
// options.add(LookupOption.HEADINGS_ONLY);
// options.add(LookupOption.HEADINGS);
// options.add(LookupOption.CHAPTER_BOOK_VERSE_NUMBER);
final String osisText = jsi.getInterleavedVersions(versions, ref, options, interlinearMode, "en").getValue();
LOGGER.debug(osisText);
final SAXBuilder sb = new SAXBuilder();
if (unicodeBreakDown) {
outputUnicode(osisText);
}
}
use of com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl in project step by STEPBible.
the class OsisReader method main.
/**
* Just shows XML on the stdout
*
* @param args not used
* @throws Exception any kind of exception
*/
public static void main(final String[] args) throws Exception {
final String version = "ESV_th";
final String ref = "Gen.2";
boolean format = true;
final Book currentBook = Books.installed().getBook(version);
final BookData bookData = new BookData(currentBook, currentBook.getKey(ref));
final Element osisFragment = bookData.getOsisFragment();
final XMLOutputter xmlOutputter = new XMLOutputter(format ? Format.getPrettyFormat() : Format.getRawFormat());
LOGGER.debug(xmlOutputter.outputString(osisFragment));
// do the test
final JSwordPassageServiceImpl jsi = new JSwordPassageServiceImpl(TestUtils.mockVersificationService(), null, null, null, TestUtils.mockVersionResolver(), null);
final List<LookupOption> options = new ArrayList<LookupOption>();
// options.add(LookupOption.DIVIDE_HEBREW);
options.add(LookupOption.NOTES);
options.add(LookupOption.HEADINGS);
options.add(LookupOption.GREEK_ACCENTS);
final String osisText = jsi.getOsisText(version, ref, options, "ESV_th", InterlinearMode.NONE).getValue();
final SAXBuilder sb = new SAXBuilder();
try {
final Document d = sb.build(new StringReader(osisText));
LOGGER.debug("Transformed is:\n {}", xmlOutputter.outputString(d));
xmlOutputter.outputString(d);
} catch (final JDOMParseException e) {
LOGGER.debug("Transformed is:\n [{}]", osisText);
}
// InterleavedOsisReader.outputUnicode(osisText);
LOGGER.debug("Double whitespace: {}", osisText.contains(" "));
}
Aggregations