Files
XuJiacheng 8337c60f98 feat: 实现Kafka批量消费与写入以提升吞吐量
引入批量处理机制,将消息缓冲并按批次写入数据库,显著提高消费性能。调整Kafka配置参数,优化消费者并发与提交策略。新增分区索引自动创建功能,并重构处理器以支持批量操作。添加降级写入逻辑以处理数据错误,同时增强指标收集以监控批量处理效果。
2026-02-09 10:50:56 +08:00

46 lines
1.5 KiB
JavaScript

import { describe, it, expect } from 'vitest';
import { buildRowsFromPayload } from '../src/processor/index.js';
describe('Processor Logic', () => {
const basePayload = {
HotelCode: '1085',
MAC: '00:1A:2B:3C:4D:5E',
HostNumber: '091123987456',
RoomNumber: '8888房',
EndPoint: '50.2.60.1:6543',
CurrentStatus: 'off',
CurrentTime: '2026-02-02T10:30:00Z',
UnixTime: 1770000235000,
LauncherVersion: '1.0.0'
};
it('should validate required fields', () => {
expect(() => buildRowsFromPayload({})).toThrow();
expect(() => buildRowsFromPayload({ ...basePayload, HotelCode: undefined })).toThrow();
});
it('should use current_status from payload for non-reboot data', () => {
const rows = buildRowsFromPayload({ ...basePayload, RebootReason: null });
expect(rows).toHaveLength(1);
expect(rows[0].current_status).toBe('off');
expect(rows[0].reboot_reason).toBeNull();
});
it('should override current_status to on for reboot data', () => {
const rows = buildRowsFromPayload({ ...basePayload, CurrentStatus: 'off', RebootReason: '0x01' });
expect(rows).toHaveLength(1);
expect(rows[0].current_status).toBe('on');
expect(rows[0].reboot_reason).toBe('0x01');
});
it('should keep empty optional fields as empty strings', () => {
const rows = buildRowsFromPayload({
...basePayload,
LauncherVersion: '',
RebootReason: ''
});
expect(rows[0].launcher_version).toBe('');
expect(rows[0].reboot_reason).toBe('');
});
});