yeg
6 天以前 2222cd054570014ddc3e9a7d72c365c505e1ba5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.battery.business.runtime;
 
import static org.junit.jupiter.api.Assertions.assertTrue;
 
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
 
/** Ticket08 三类测试数据持久化结构契约。 */
class TestDataPersistenceMigrationContractTest
{
    @Test
    void stepAndCycleRecordsKeepBindingReceptionTimeAndStableDedupeKey()
    {
        String sql = resource("db/migration-final/V3__test_data_persistence.sql");
 
        assertTrue(sql.contains("ALTER TABLE t_test_realtime_record"));
        assertTrue(sql.contains("source_identity VARCHAR(256) NOT NULL"));
        assertTrue(sql.contains("source_record_id VARCHAR(128) NULL"));
        assertTrue(sql.contains("ALTER TABLE t_test_step_record"));
        assertTrue(sql.contains("ALTER TABLE t_test_cycle_record"));
        assertTrue(sql.contains("binding_id BIGINT NOT NULL"));
        assertTrue(sql.contains("server_received_at_utc DATETIME(3) NOT NULL"));
        assertTrue(sql.contains("dedupe_key VARCHAR(512) NOT NULL"));
        assertTrue(sql.contains("UNIQUE KEY uk_step_dedupe"));
        assertTrue(sql.contains("UNIQUE KEY uk_cycle_dedupe"));
    }
 
    private static String resource(String path)
    {
        try (InputStream stream = TestDataPersistenceMigrationContractTest.class.getClassLoader()
                .getResourceAsStream(path))
        {
            if (stream == null) throw new AssertionError("缺少资源 " + path);
            return new String(stream.readAllBytes(), StandardCharsets.UTF_8);
        }
        catch (Exception exception)
        {
            throw new AssertionError("无法读取资源 " + path, exception);
        }
    }
}