Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/kotlin/com/flo/nem12/config/DatabaseConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ object DatabaseConfig {
CREATE TABLE IF NOT EXISTS failure_reading (
id TEXT PRIMARY KEY,
line_number INTEGER NOT NULL,
nmi TEXT,
nmi TEXT,
interval_index INTEGER,
raw_value TEXT NOT NULL,
failure_reason TEXT NOT NULL,
timestamp TIMESTAMP
timestamp TIMESTAMP,
is_processed BOOLEAN NOT NULL DEFAULT 0
)
"""

const val INSERT_FAILED_READING_SQL = """
INSERT INTO failure_reading (id, line_number, nmi, interval_index, raw_value, failure_reason, timestamp)
VALUES (?, ?, ?, ?, ?, ?, ?)
INSERT INTO failure_reading (id, line_number, nmi, interval_index, raw_value, failure_reason, timestamp, is_processed)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
"""
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class FailureReadingsRepositoryImpl(
val utcTimestamp = entity.timestamp?.let { aestToUtc(it) }
statement.setString(7, utcTimestamp?.format(timestampFormatter))

// Set is_processed to false (will be managed by separate failure processing system)
statement.setBoolean(8, false)

// Update statistics
statistics[entity.reason] = statistics.getOrDefault(entity.reason, 0) + 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.sql.DriverManager
import java.time.LocalDateTime
import kotlin.io.path.deleteIfExists
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class FailureReadingsRepositoryTest {
Expand Down Expand Up @@ -264,4 +265,31 @@ class FailureReadingsRepositoryTest {
assertEquals(5, resultSet.getInt("cnt"))
connection.close()
}

@Test
fun `should insert failure record with is_processed set to false`() {
// Given
val dbPath = testDbPath
val failure = FailureRecord(
lineNumber = 1,
nmi = "1234567890",
intervalIndex = 0,
rawValue = "invalid",
reason = FailureReason.EMPTY_VALUE,
timestamp = LocalDateTime.of(2024, 1, 1, 0, 0)
)
val connection = DriverManager.getConnection("jdbc:sqlite:$dbPath")

// When
FailureReadingsRepositoryImpl(connection, 10).use { repository ->
repository.save(failure)
}

// Then
val resultSet = connection.createStatement()
.executeQuery("SELECT is_processed FROM failure_reading")
assertTrue(resultSet.next())
assertFalse(resultSet.getBoolean("is_processed"))
connection.close()
}
}