Skip to content

Commit

Permalink
Merge pull request #263 from dkpro/refactoring/164-Introduce-checkstyle
Browse files Browse the repository at this point in the history
#164 - Introduce checkstyle
  • Loading branch information
reckart authored Oct 31, 2023
2 parents 0c77ee6 + d047e17 commit 3a56be3
Show file tree
Hide file tree
Showing 392 changed files with 52,718 additions and 45,705 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
distribution: temurin
java-version: ${{ matrix.java }}
- name: Build with Maven
run: mvn -V clean package --no-transfer-progress
run: mvn -V clean verify --no-transfer-progress
78 changes: 48 additions & 30 deletions dkpro-jwpl-api/src/it/java/org/dkpro/jwpl/api/PerformanceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@
*/
package org.dkpro.jwpl.api;

import org.dkpro.jwpl.api.exception.WikiApiException;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.junit.jupiter.api.BeforeEach;
import org.dkpro.jwpl.api.exception.WikiApiException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PerformanceIT implements WikiConstants {
public class PerformanceIT
implements WikiConstants
{

private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final Logger logger = LoggerFactory
.getLogger(MethodHandles.lookup().lookupClass());

private static Wikipedia wiki;
private static int retrievedNumberOfPages;
Expand All @@ -43,111 +44,128 @@ public class PerformanceIT implements WikiConstants {
private static PerformanceTest pt;

@BeforeAll
public static void setupWikipedia() throws WikiApiException {
public static void setupWikipedia() throws WikiApiException
{
Properties configuration = loadConfiguration();
retrievedNumberOfPages = Integer.parseInt(configuration.getProperty("performance.pages.retrieved"));
retrievedNumberOfPages = Integer
.parseInt(configuration.getProperty("performance.pages.retrieved"));
DatabaseConfiguration dbConfig = obtainITDBConfiguration(configuration);
wiki = new Wikipedia(dbConfig);
int maxiCycles = Integer.parseInt(configuration.getProperty("performance.cycles.maxi"));
int pageCycles = Integer.parseInt(configuration.getProperty("performance.cycles.page"));
pt = new PerformanceTest(wiki, maxiCycles, pageCycles);
}

private static DatabaseConfiguration obtainITDBConfiguration(Properties configuration) {
private static DatabaseConfiguration obtainITDBConfiguration(Properties configuration)
{
String name = configuration.getProperty("database.name");
String host = configuration.getProperty("database.host");
String user = configuration.getProperty("database.user");
String password = configuration.getProperty("database.password");
// String host, String database, String user, String password, Language language
return new DatabaseConfiguration(
"org.mariadb.jdbc.Driver",
"jdbc:mariadb://" + host + "/" + name + "?serverTimezone=Europe/Berlin&autoReconnect=true&useSSL=false",
return new DatabaseConfiguration("org.mariadb.jdbc.Driver",
"jdbc:mariadb://" + host + "/" + name
+ "?serverTimezone=Europe/Berlin&autoReconnect=true&useSSL=false",
host, name, user, password, Language.english);
}

private static Properties loadConfiguration() {
private static Properties loadConfiguration()
{
Properties dbConfigProperties = new Properties();
InputStream resourceStream = checkResourceExists("jwpl-env-configuration.properties");
if(resourceStream == null) {
if (resourceStream == null) {
throw new RuntimeException("Can't find JWPL IT DB configuration in the classpath!");
}
else {
try (BufferedInputStream stream = new BufferedInputStream(resourceStream)) {
dbConfigProperties.load(stream);
} catch(IOException e) {
}
catch (IOException e) {
logger.error(e.getLocalizedMessage(), e);
throw new RuntimeException("Can't load JWPL IT DB configuration!");
}
return dbConfigProperties;
}
}

private static InputStream checkResourceExists(String resourceName) {
private static InputStream checkResourceExists(String resourceName)
{
return Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
}

@BeforeEach
public void setup() throws WikiApiException {
public void setup() throws WikiApiException
{

}

@Test
public void testPerformanceLoadPagesIntern() throws WikiApiException {
public void testPerformanceLoadPagesIntern() throws WikiApiException
{
logger.debug("intern page loading");
pt.loadPagesTest("intern");

}

@Test
public void testPerformanceLoadPagesExtern() throws WikiApiException {
public void testPerformanceLoadPagesExtern() throws WikiApiException
{
logger.debug("extern page loading");
pt.loadPagesTest("extern");
}

@Test
public void testPerformanceLoadPagesAndAccessFieldsIntern() throws WikiApiException {
public void testPerformanceLoadPagesAndAccessFieldsIntern() throws WikiApiException
{
logger.debug("intern page loading and field accessing");
pt.loadPagesAndAccessFieldsTest("intern");
}

@Test
public void testPerformanceLoadPagesAndAccessFieldsExtern() throws WikiApiException {
public void testPerformanceLoadPagesAndAccessFieldsExtern() throws WikiApiException
{
logger.debug("extern page loading and field accessing");
pt.loadPagesAndAccessFieldsTest("extern");
pt.loadPagesAndAccessFieldsTest("extern");
}

@Test
public void testPerformancePageIteratorBuffer1() throws WikiApiException {
public void testPerformancePageIteratorBuffer1() throws WikiApiException
{
logger.debug("Test: retrieve 4000 pages - buffer = '{}' ...", retrievedNumberOfPages, 1);
pt.loadPageAndIterate(retrievedNumberOfPages, 1, wiki);
}

@Test
public void testPerformancePageIteratorBuffer10() throws WikiApiException {
public void testPerformancePageIteratorBuffer10() throws WikiApiException
{
logger.debug("Test: retrieve 4000 pages - buffer = '{}' ...", retrievedNumberOfPages, 10);
pt.loadPageAndIterate(retrievedNumberOfPages, 10, wiki);
}

@Test
public void testPerformancePageIteratorBuffer50() throws WikiApiException {
public void testPerformancePageIteratorBuffer50() throws WikiApiException
{
logger.debug("Test: retrieve 4000 pages - buffer = '{}' ...", retrievedNumberOfPages, 50);
pt.loadPageAndIterate(retrievedNumberOfPages, 50, wiki);
}

@Test
public void testPerformancePageIteratorBuffer100() throws WikiApiException {
public void testPerformancePageIteratorBuffer100() throws WikiApiException
{
logger.debug("Test: retrieve 4000 pages - buffer = '{}' ...", retrievedNumberOfPages, 100);
pt.loadPageAndIterate(retrievedNumberOfPages, 100, wiki);
}

@Test
public void testPerformancePageIteratorBuffer200() throws WikiApiException {
public void testPerformancePageIteratorBuffer200() throws WikiApiException
{
logger.debug("Test: retrieve 4000 pages - buffer = '{}' ...", retrievedNumberOfPages, 200);
pt.loadPageAndIterate(retrievedNumberOfPages, 200, wiki);
}

@Test
public void testPerformancePageIteratorBuffer500() throws WikiApiException {
public void testPerformancePageIteratorBuffer500() throws WikiApiException
{
logger.debug("Test: retrieve 4000 pages - buffer = '{}' ...", retrievedNumberOfPages, 500);
pt.loadPageAndIterate(retrievedNumberOfPages, 500, wiki);
}
Expand Down
72 changes: 42 additions & 30 deletions dkpro-jwpl-api/src/it/java/org/dkpro/jwpl/api/PerformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,28 @@
*/
package org.dkpro.jwpl.api;

import org.dkpro.jwpl.api.exception.WikiApiException;
import org.dkpro.jwpl.util.GraphUtilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.dkpro.jwpl.api.exception.WikiApiException;
import org.dkpro.jwpl.util.GraphUtilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Encapsulates the integration test code that stresses a Wikipedia backend to check the performance of it.
* Encapsulates the integration test code that stresses a Wikipedia backend to check the performance
* of it.
*/
class PerformanceTest {
class PerformanceTest
{

private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final Logger logger = LoggerFactory
.getLogger(MethodHandles.lookup().lookupClass());

private final Wikipedia wiki;

Expand All @@ -47,21 +50,23 @@ class PerformanceTest {
private final int maxiCycles;
private final int pageCycles;

PerformanceTest(Wikipedia pWiki, int maxiCycles, int pageCycles) throws WikiApiException {
PerformanceTest(Wikipedia pWiki, int maxiCycles, int pageCycles) throws WikiApiException
{
this.wiki = pWiki;
this.maxiCycles = maxiCycles;
this.pageCycles = pageCycles;
pageIDs = wiki.__getPages();
initializeLists(pageIDs);
}

private void initializeLists(Set<Integer> allPageIDs) throws WikiApiException {
private void initializeLists(Set<Integer> allPageIDs) throws WikiApiException
{
randomIdList = new ArrayList<>();
randomTitleList = new ArrayList<>();

for (int j=0; j<maxiCycles; j++) {
for (int j = 0; j < maxiCycles; j++) {
Set<Integer> randomPageIds = GraphUtilities.getRandomPageSubset(allPageIDs, pageCycles);
List<Integer> randomPageIdList = new ArrayList<>( randomPageIds );
List<Integer> randomPageIdList = new ArrayList<>(randomPageIds);
randomIdList.add(randomPageIdList);

List<String> randomPageTitles = new ArrayList<>();
Expand All @@ -74,13 +79,14 @@ private void initializeLists(Set<Integer> allPageIDs) throws WikiApiException {

}

void loadPagesTest(String mode) throws WikiApiException {
void loadPagesTest(String mode) throws WikiApiException
{
double averageThroughput = 0;
for (int j=0; j<maxiCycles; j++) {
for (int j = 0; j < maxiCycles; j++) {
double averageTime = 0;
for (int i=0; i<pageCycles; i++) {
for (int i = 0; i < pageCycles; i++) {

long id = wiki.__getPageHibernateId( randomIdList.get(j).get(i) );
long id = wiki.__getPageHibernateId(randomIdList.get(j).get(i));
String title = randomTitleList.get(j).get(i);

double startTime = System.currentTimeMillis();
Expand All @@ -101,15 +107,16 @@ void loadPagesTest(String mode) throws WikiApiException {

logger.debug("-----------------");
logger.debug("average throughput: {} pages/ms", averageThroughput);
logger.debug("average throughput: {} pages/s", averageThroughput*1000);
logger.debug("average throughput: {} pages/s", averageThroughput * 1000);
logger.debug("-----------------");
}

void loadPagesAndAccessFieldsTest(String mode) throws WikiApiException {
void loadPagesAndAccessFieldsTest(String mode) throws WikiApiException
{
double averageThroughput = 0;
for (int j=0; j<maxiCycles; j++) {
for (int j = 0; j < maxiCycles; j++) {
double averageTime = 0;
for (int i=0; i<pageCycles; i++) {
for (int i = 0; i < pageCycles; i++) {

Set<Integer> page = GraphUtilities.getRandomPageSubset(pageIDs, 1);
Iterator<Integer> it = page.iterator();
Expand All @@ -134,20 +141,24 @@ void loadPagesAndAccessFieldsTest(String mode) throws WikiApiException {

logger.debug("-----------------");
logger.debug("average throughput: {} pages/ms", averageThroughput);
logger.debug("average throughput: {} pages/s", averageThroughput*1000); logger.debug("-----------------");
logger.debug("average throughput: {} pages/s", averageThroughput * 1000);
logger.debug("-----------------");
}

private void loadPage(long id) throws WikiApiException {
private void loadPage(long id) throws WikiApiException
{
Page page = new Page(this.wiki, id);
assertNotNull(page);
}

private void loadPage(String title) throws WikiApiException {
private void loadPage(String title) throws WikiApiException
{
Page page = wiki.getPage(title);
assertNotNull(page);
}

private void loadPageAndAccessFields_intern(long id) throws WikiApiException {
private void loadPageAndAccessFields_intern(long id) throws WikiApiException
{
Page page = new Page(this.wiki, id);
Set<Integer> inLinks = page.getInlinkIDs();
assertNotNull(inLinks);
Expand All @@ -157,7 +168,8 @@ private void loadPageAndAccessFields_intern(long id) throws WikiApiException {
assertNotNull(text);
}

private void loadPageAndAccessFields_extern(long id) throws WikiApiException {
private void loadPageAndAccessFields_extern(long id) throws WikiApiException
{
Page page = new Page(this.wiki, id);
Set<Page> inLinks = page.getInlinks();
assertNotNull(inLinks);
Expand All @@ -168,14 +180,14 @@ private void loadPageAndAccessFields_extern(long id) throws WikiApiException {
}

/**
* This is a test class for the version of PageIterator, that buffers a
* certain number of pages in order to gain efficiency.
* We get the same number of pages from a Wikipedia using
* different buffer sizes and return the performance.
* This is a test class for the version of PageIterator, that buffers a certain number of pages
* in order to gain efficiency. We get the same number of pages from a Wikipedia using different
* buffer sizes and return the performance.
* <p>
* For an unbuffered iterator set bufferSize to 1.
*/
void loadPageAndIterate(int numberOfPages, int bufferSize, Wikipedia wiki) {
void loadPageAndIterate(int numberOfPages, int bufferSize, Wikipedia wiki)
{
long from = System.currentTimeMillis();
Iterator<Page> pages = wiki.getPages(bufferSize).iterator();
int counter = 0;
Expand Down
Loading

0 comments on commit 3a56be3

Please sign in to comment.