Skip to content

Commit

Permalink
Improve database storage
Browse files Browse the repository at this point in the history
  • Loading branch information
jacodg committed Dec 20, 2023
1 parent b557553 commit 80c5cc7
Show file tree
Hide file tree
Showing 14 changed files with 389 additions and 138 deletions.
4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Ladybug Test Tool release notes
Upcoming (2.3)
--------------

- Add Liquibase xml files (remove experimental version from test jar)
- Add alternative destination to proxy storage
- Implement database test storage
- Optionally store report xml in database
- Fix performance impact of max memory usage check
- Add maxStorageSize to DatabaseStorage
- Add HideMessageTransformer and LinkingMessageTransformer
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/nl/nn/testtool/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@
import nl.nn.testtool.transform.ReportXmlTransformer;

/**
* <p>
* Default configuration / wiring of beans to minimize the Spring (xml) / Quarkus configuration needed to integrate
* Ladybug into an application.
* </p>
*
* <p>
* For classes with <code>@Inject</code>, <code>@Autowired</code> and/or <code>@PostConstruct</code> annotations add
* <code>@Bean</code> methods to this class for Spring with <code>@Scope("singleton")</code> or
* <code>@Scope("prototype")</code> and add <code>@Dependent</code> or <code>@Singleton</code> to those classes for
* Quarkus.
* <code>@Scope("prototype")</code> and for Quarkus add <code>@Produces</code> and optionally <code>@Singleton</code> to
* this class or add <code>@Dependent</code> or <code>@Singleton</code> to the classes with <code>@Inject</code>,
* <code>@Autowired</code> and/or <code>@PostConstruct</code> annotations.
* </p>
*
* <p>
Expand All @@ -74,10 +80,10 @@
* </ul>
*
* Quarkus related:
*
*
* <ul>
* <li>Quarkus doesn't wire and init beans returned by the methods in this class but will do it for
* <code>@Dependent</code> and <code>@Singleton</code> classes</li>
* <li>Quarkus doesn't wire and init beans returned by the methods in this class but will do it for beans created
* based on classes that contain <code>@Dependent</code> or <code>@Singleton</code></li>
* <li>Default wiring using <code>@DefaultBean</code> (https://quarkus.io/guides/cdi-reference#default_beans) can be
* overridden in an application using Ladybug as a library.</li>
* </ul>
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/nl/nn/testtool/MetadataExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,24 @@
*/
package nl.nn.testtool;

import java.lang.invoke.MethodHandles;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Iterator;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.Getter;
import lombok.Setter;

/**
* @author Jaco de Groot
*/
public class MetadataExtractor {
private static Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final int VALUE_TYPE_OBJECT = 0;
public static final int VALUE_TYPE_STRING = 1;
public static final int VALUE_TYPE_GUI = 2;
private static final DateTimeFormatter FORMAT_DATE_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").withZone(ZoneId.systemDefault());
public List<MetadataFieldExtractor> extraMetadataFieldExtractors;

public void setExtraMetadataFieldExtractors(List<MetadataFieldExtractor> extraMetadataFieldExtractors) {
this.extraMetadataFieldExtractors = extraMetadataFieldExtractors;
}
public @Setter @Getter List<MetadataFieldExtractor> extraMetadataFieldExtractors;

public String getLabel(String metadataName) {
// TODO use reflection or spring or something like that for getLabel and getShortLabel?
Expand Down Expand Up @@ -249,4 +243,16 @@ public Object fromStringtoObject(String metadataName, String metadataValue) {
return metadataValue;
}

public boolean isInteger(String metadataName) {
return metadataName.equals("storageId") || metadataName.equals("numberOfCheckpoints");
}

public boolean isLong(String metadataName) {
return metadataName.equals("duration") || metadataName.equals("estimatedMemoryUsage") || metadataName.equals("storageSize");
}

public boolean isTimestamp(String metadataName) {
return metadataName.equals("endTime");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2023 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package nl.nn.testtool.echo2.test;

import java.util.Comparator;
import java.util.List;

public class MetadataRecordComparator implements Comparator<List<Object>> {
private int pathPosition;
private int namePosition;

MetadataRecordComparator(int pathPosition, int namePosition) {
this.pathPosition = pathPosition;
this.namePosition = namePosition;
}

public int compare(List<Object> arg0, List<Object> arg1) {
String string0 = (String)arg0.get(pathPosition);
if (namePosition > -1) {
string0 = string0 + (String)arg0.get(2);
}
if (string0 == null) {
string0 = "/";
}
String string1 = (String)arg1.get(pathPosition);
if (namePosition > -1) {
string1 = string1 + (String)arg1.get(2);
}
if (string1 == null) {
string1 = "/";
}
return string0.compareTo(string1);
}

}
13 changes: 1 addition & 12 deletions src/main/java/nl/nn/testtool/echo2/test/TestComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -449,7 +448,7 @@ public void display(String path, Set<String> selectedStorageIds) {
}
}
boolean directChildReportsPresent = false;
Collections.sort(metadata, new MetadataComparator());
Collections.sort(metadata, new MetadataRecordComparator(1, 2));
Iterator<List<Object>> metadataIterator;
// First direct child's (path.equals(metadataPath))
metadataIterator = metadata.iterator();
Expand Down Expand Up @@ -1065,13 +1064,3 @@ public WindowPane getUploadOptionsWindow() {
}

}

class MetadataComparator implements Comparator<List<Object>> {

public int compare(List<Object> arg0, List<Object> arg1) {
String string0 = (String)arg0.get(1) + (String)arg0.get(2);
String string1 = (String)arg1.get(1) + (String)arg1.get(2);
return string0.compareTo(string1);
}

}
4 changes: 2 additions & 2 deletions src/main/java/nl/nn/testtool/echo2/test/TreePane.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020, 2022 WeAreFrank!, 2018 Nationale-Nederlanden
Copyright 2020, 2022-2023 WeAreFrank!, 2018 Nationale-Nederlanden
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -119,6 +119,7 @@ public void redisplayReports(String selectPath, Set<String> selectedStorageIds)
// TODO iets doen
e.printStackTrace();
}
Collections.sort(metadata, new MetadataRecordComparator(1, -1));
List<String> pathsToAdd = new ArrayList<String>();
Iterator<List<Object>> metadataIterator = metadata.iterator();
while (metadataIterator.hasNext()) {
Expand All @@ -131,7 +132,6 @@ public void redisplayReports(String selectPath, Set<String> selectedStorageIds)
pathsToAdd.add(path);
}
}
Collections.sort(pathsToAdd);
DefaultMutableTreeNode selectNode = addPaths(pathsToAdd, rootNode, selectPath);
if (selectNode == null) {
selectNode = rootNode;
Expand Down
Loading

0 comments on commit 80c5cc7

Please sign in to comment.