fix-tests-cleanup
This commit is contained in:
@@ -4,6 +4,8 @@ import auctiora.db.*;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jdbi.v3.core.Jdbi;
|
import org.jdbi.v3.core.Jdbi;
|
||||||
|
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,8 +26,10 @@ public class DatabaseService {
|
|||||||
/**
|
/**
|
||||||
* Constructor for programmatic instantiation (tests, CLI tools).
|
* Constructor for programmatic instantiation (tests, CLI tools).
|
||||||
*/
|
*/
|
||||||
|
private final String url;
|
||||||
|
|
||||||
public DatabaseService(String dbPath) {
|
public DatabaseService(String dbPath) {
|
||||||
String url = "jdbc:sqlite:" + dbPath + "?journal_mode=WAL&busy_timeout=10000";
|
this.url = "jdbc:sqlite:" + dbPath + "?journal_mode=WAL&busy_timeout=10000";
|
||||||
this.jdbi = Jdbi.create(url);
|
this.jdbi = Jdbi.create(url);
|
||||||
|
|
||||||
// Initialize schema
|
// Initialize schema
|
||||||
@@ -42,6 +46,8 @@ public class DatabaseService {
|
|||||||
*/
|
*/
|
||||||
public DatabaseService(Jdbi jdbi) {
|
public DatabaseService(Jdbi jdbi) {
|
||||||
this.jdbi = jdbi;
|
this.jdbi = jdbi;
|
||||||
|
this.url = null; // Use null as this constructor doesn't use the URL
|
||||||
|
|
||||||
DatabaseSchema.ensureSchema(jdbi);
|
DatabaseSchema.ensureSchema(jdbi);
|
||||||
|
|
||||||
this.lotRepository = new LotRepository(jdbi);
|
this.lotRepository = new LotRepository(jdbi);
|
||||||
@@ -69,7 +75,53 @@ public class DatabaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronized void upsertLot(Lot lot) {
|
synchronized void upsertLot(Lot lot) {
|
||||||
lotRepository.upsert(lot);
|
retry(() -> {
|
||||||
|
try (var connection = DriverManager.getConnection(url)) {
|
||||||
|
connection.setAutoCommit(false); // Start transaction
|
||||||
|
lotRepository.upsert(lot); // Perform update
|
||||||
|
connection.commit(); // Commit transaction
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException("Failed to upsert lot", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void upsertLots(List<Lot> lots) { // Batch import with transactions
|
||||||
|
retry(() -> {
|
||||||
|
try (var connection = DriverManager.getConnection(url)) {
|
||||||
|
connection.setAutoCommit(false); // Start transaction
|
||||||
|
for (Lot lot : lots) {
|
||||||
|
lotRepository.upsert(lot); // Upsert individual lot
|
||||||
|
}
|
||||||
|
connection.commit(); // Commit transaction
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException("Failed to upsert lots", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retry logic for transient database failures
|
||||||
|
private void retry(Runnable action) {
|
||||||
|
final int maxRetries = 3;
|
||||||
|
for (int attempt = 1; attempt <= maxRetries; attempt++) {
|
||||||
|
try {
|
||||||
|
action.run(); // Attempt action
|
||||||
|
return; // Exit on success
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
boolean isBusy = e.getCause() instanceof SQLException
|
||||||
|
&& e.getCause().getMessage().contains("[SQLITE_BUSY]");
|
||||||
|
if (isBusy && attempt < maxRetries) {
|
||||||
|
log.warn("Database locked, retrying {} of {}", attempt, maxRetries);
|
||||||
|
try {
|
||||||
|
Thread.sleep(500L * attempt); // Backoff
|
||||||
|
} catch (InterruptedException interrupted) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw e; // Non-retryable error or max retries exceeded
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void upsertLotWithIntelligence(Lot lot) {
|
synchronized void upsertLotWithIntelligence(Lot lot) {
|
||||||
@@ -212,7 +264,7 @@ public class DatabaseService {
|
|||||||
// ==================== LEGACY RECORDS ====================
|
// ==================== LEGACY RECORDS ====================
|
||||||
// Keep records for backward compatibility with existing code
|
// Keep records for backward compatibility with existing code
|
||||||
|
|
||||||
public record ImageRecord(int id, long lotId, String url, String filePath, String labels) {}
|
public record ImageRecord(int id, long lotId, String url, String filePath, String labels) { }
|
||||||
|
|
||||||
public record ImageDetectionRecord(int id, long lotId, String filePath) {}
|
public record ImageDetectionRecord(int id, long lotId, String filePath) { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class NotificationServiceTest {
|
|||||||
@DisplayName("Should include both desktop and email when SMTP configured")
|
@DisplayName("Should include both desktop and email when SMTP configured")
|
||||||
void testBothNotificationChannels() {
|
void testBothNotificationChannels() {
|
||||||
var service = new NotificationService(
|
var service = new NotificationService(
|
||||||
"smtp:user@gmail.com:password:recipient@example.com"
|
"smtp:michael.bakker1986@gmail.com:agrepolhlnvhipkv:michael.bakker1986@gmail.com"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Both desktop and email should be attempted
|
// Both desktop and email should be attempted
|
||||||
|
|||||||
65
src/test/resources/application.properties
Normal file
65
src/test/resources/application.properties
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
# Application Configuration
|
||||||
|
# Values will be injected from pom.xml during build
|
||||||
|
quarkus.application.name=${project.artifactId}
|
||||||
|
quarkus.application.version=${project.version}
|
||||||
|
# Custom properties for groupId if needed
|
||||||
|
application.groupId=${project.groupId}
|
||||||
|
application.artifactId=${project.artifactId}
|
||||||
|
application.version=${project.version}
|
||||||
|
|
||||||
|
|
||||||
|
# HTTP Configuration
|
||||||
|
quarkus.http.port=8081
|
||||||
|
# ========== DEVELOPMENT (quarkus:dev) ==========
|
||||||
|
%dev.quarkus.http.host=127.0.0.1
|
||||||
|
# ========== PRODUCTION (Docker/JAR) ==========
|
||||||
|
%prod.quarkus.http.host=0.0.0.0
|
||||||
|
# ========== TEST PROFILE ==========
|
||||||
|
%test.quarkus.http.host=localhost
|
||||||
|
|
||||||
|
# Enable CORS for frontend development
|
||||||
|
quarkus.http.cors=true
|
||||||
|
quarkus.http.cors.origins=*
|
||||||
|
quarkus.http.cors.methods=GET,POST,PUT,DELETE,OPTIONS
|
||||||
|
quarkus.http.cors.headers=accept,authorization,content-type,x-requested-with
|
||||||
|
|
||||||
|
# Logging Configuration
|
||||||
|
quarkus.log.console.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
|
||||||
|
quarkus.log.console.level=INFO
|
||||||
|
|
||||||
|
# Development mode settings
|
||||||
|
%dev.quarkus.log.console.level=DEBUG
|
||||||
|
%dev.quarkus.live-reload.instrumentation=true
|
||||||
|
|
||||||
|
# JVM Arguments for native access (Jansi, OpenCV, etc.)
|
||||||
|
quarkus.native.additional-build-args=--enable-native-access=ALL-UNNAMED
|
||||||
|
|
||||||
|
# Production optimizations
|
||||||
|
%prod.quarkus.package.type=fast-jar
|
||||||
|
%prod.quarkus.http.enable-compression=true
|
||||||
|
|
||||||
|
# Static resources
|
||||||
|
quarkus.http.enable-compression=true
|
||||||
|
quarkus.rest.path=/
|
||||||
|
quarkus.http.root-path=/
|
||||||
|
|
||||||
|
# Auction Monitor Configuration
|
||||||
|
auction.database.path=/mnt/okcomputer/output/cache.db
|
||||||
|
auction.images.path=/mnt/okcomputer/output/images
|
||||||
|
# auction.notification.config=desktop
|
||||||
|
# Format: smtp:username:password:recipient_email
|
||||||
|
auction.notification.config=smtp:michael.bakker1986@gmail.com:agrepolhlnvhipkv:michael.bakker1986@gmail.com
|
||||||
|
|
||||||
|
auction.yolo.config=/mnt/okcomputer/output/models/yolov4.cfg
|
||||||
|
auction.yolo.weights=/mnt/okcomputer/output/models/yolov4.weights
|
||||||
|
auction.yolo.classes=/mnt/okcomputer/output/models/coco.names
|
||||||
|
|
||||||
|
# HTTP Rate Limiting Configuration
|
||||||
|
# Prevents overloading external services and getting blocked
|
||||||
|
auction.http.rate-limit.default-max-rps=2
|
||||||
|
auction.http.rate-limit.troostwijk-max-rps=1
|
||||||
|
auction.http.timeout-seconds=30
|
||||||
|
|
||||||
|
# Health Check Configuration
|
||||||
|
quarkus.smallrye-health.root-path=/health
|
||||||
|
|
||||||
Reference in New Issue
Block a user