Skip to content

Commit

Permalink
common | fixed cache tests due to storing mechanism update
Browse files Browse the repository at this point in the history
  • Loading branch information
Minyewoo committed Apr 22, 2024
1 parent c6d49ea commit 93687b9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ void main() {
expect(await cache.getAll(), equals(const <DsDataPoint>[]));
});
test('get(pointName) returns null if no initial cache provided', () async {
final testPointNames = ['Winch2.EncoderBR1', 'ConstantTension.Active', 'HPA.LowNiroPressure', 'HPU.HighPressure', 'Winch1.Overload'];
final testPointNames = [
DsPointName('/Winch2.EncoderBR1'),
DsPointName('/ConstantTension.Active'),
DsPointName('/HPA.LowNiroPressure'),
DsPointName('/HPU.HighPressure'),
DsPointName('/Winch1.Overload'),
];
final cache = DsClientDelayedCache(
primaryCache: FakeDsClientCache(),
secondaryCache: FakeDsClientCache(),
Expand All @@ -26,16 +32,16 @@ void main() {
});
final initialCaches = [
{
'': DsDataPoint(type: DsDataType.bool, name: DsPointName('/'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/': DsDataPoint(type: DsDataType.bool, name: DsPointName('/'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
},
{
'abc': DsDataPoint(type: DsDataType.bool, name: DsPointName('/'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'123': DsDataPoint(type: DsDataType.bool, name: DsPointName('/'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/abc': DsDataPoint(type: DsDataType.bool, name: DsPointName('/abc'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/123': DsDataPoint(type: DsDataType.bool, name: DsPointName('/123'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
},
{
'point1': DsDataPoint(type: DsDataType.real, name: DsPointName('/test/point1'), value: 474.20942, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'point2': DsDataPoint(type: DsDataType.integer, name: DsPointName('/test/point2'), value: 342134, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'point3': DsDataPoint(type: DsDataType.bool, name: DsPointName('/test/point3'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/point1': DsDataPoint(type: DsDataType.real, name: DsPointName('/test/point1'), value: 474.20942, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/point2': DsDataPoint(type: DsDataType.integer, name: DsPointName('/test/point2'), value: 342134, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/point3': DsDataPoint(type: DsDataType.bool, name: DsPointName('/test/point3'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
},
];
test('getAll() returns provided initial cache', () async {
Expand All @@ -52,7 +58,7 @@ void main() {
final cacheEntries = initialCache.entries.toList();
final cache = DsClientMemoryCache(initialCache: initialCache);
for(var i=0; i<cacheEntries.length; i++) {
final pointName = cacheEntries[i].key;
final pointName = DsPointName(cacheEntries[i].key);
final point = cacheEntries[i].value;
final option = await cache.get(pointName);
expect(option, isA<Some>());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:hmi_core/hmi_core_option.dart';
import 'package:hmi_core/src/core/entities/ds_data_point.dart';
import 'package:hmi_core/hmi_core.dart';
import 'package:hmi_networking/src/core/ds_client/cache/ds_client_cache.dart';

final class FakeDsClientCache implements DsClientCache {
Expand All @@ -22,7 +21,7 @@ final class FakeDsClientCache implements DsClientCache {
}

@override
Future<Option<DsDataPoint>> get(String pointName) async {
Future<Option<DsDataPoint>> get(DsPointName pointName) async {
final point = internalMap[pointName];
return switch(point) {
null => const None() as Option<DsDataPoint>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
);
for(final point in testPoints) {
await cache.add(point);
expect(fakeFile.internalMap[point.name.name], equals(point));
expect(fakeFile.internalMap[point.name.toString()], equals(point));
}
});
test('addMany(points) inserts multiple points to file', () async {
Expand Down Expand Up @@ -60,7 +60,7 @@ void main() {
DsDataPoint(type: DsDataType.integer, name: DsPointName('/test/point1'), value: 342134, status: DsStatus.ok, timestamp: "2024-03-04T19:25:29.228612", cot: DsCot.inf),
DsDataPoint(type: DsDataType.bool, name: DsPointName('/test/point1'), value: false, status: DsStatus.timeInvalid, timestamp: "2024-03-04T19:25:29.228612", cot: DsCot.inf),
];
const pointName = 'point1';
const pointName = '/test/point1';
final fakeFile = FakeDsCacheFile();
final cache = DsClientFileCache(
cacheFile: fakeFile,
Expand All @@ -70,17 +70,17 @@ void main() {
for(final point in uniqueTestPoints.sublist(1)) {
expect(
fakeFile.internalMap[pointName], equals(oldPoint),
reason: 'Should be equal to old value before an addition.',
reason: 'Should be equal to old value before an addition. Internal map: ${fakeFile.internalMap}',
);
final newPoint = point;
expect(
newPoint, isNot(equals(oldPoint)),
reason: 'Points should have different attributes in this test.',
reason: 'Points should have different attributes in this test. Internal map: ${fakeFile.internalMap}',
);
await cache.add(newPoint);
expect(
fakeFile.internalMap[pointName], equals(newPoint),
reason: 'Should be equal to new value after an addition.',
reason: 'Should be equal to new value after an addition. Internal map: ${fakeFile.internalMap}',
);
oldPoint = newPoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ void main() {
expect(await cache.getAll(), equals(const <DsDataPoint>[]));
});
test('get(pointName) returns no points if file doesn\'t exist', () async {
final testPointNames = ['Winch2.EncoderBR1', 'ConstantTension.Active', 'HPA.LowNiroPressure', 'HPU.HighPressure', 'Winch1.Overload'];
final testPointNames = [
DsPointName('/Winch2.EncoderBR1'),
DsPointName('/ConstantTension.Active'),
DsPointName('/HPA.LowNiroPressure'),
DsPointName('/HPU.HighPressure'),
DsPointName('/Winch1.Overload'),
];
final cache = DsClientFileCache(
cacheFile: FakeDsCacheFile(),
);
Expand All @@ -23,16 +29,16 @@ void main() {
});
final initialCaches = [
{
'': DsDataPoint<bool>(type: DsDataType.bool, name: DsPointName('/'), value: false, status: DsStatus.ok, timestamp: "2024-03-04T19:25:29.228612", cot: DsCot.inf),
'/': DsDataPoint<bool>(type: DsDataType.bool, name: DsPointName('/'), value: false, status: DsStatus.ok, timestamp: "2024-03-04T19:25:29.228612", cot: DsCot.inf),
},
{
'abc': DsDataPoint<bool>(type: DsDataType.bool, name: DsPointName('/'), value: false, status: DsStatus.ok, timestamp: "2024-03-04T19:27:53.149811", cot: DsCot.inf),
'123': DsDataPoint<bool>(type: DsDataType.bool, name: DsPointName('/'), value: true, status: DsStatus.ok, timestamp: "2024-03-04T19:28:18.812448", cot: DsCot.inf),
'/abc': DsDataPoint<bool>(type: DsDataType.bool, name: DsPointName('/abc'), value: false, status: DsStatus.ok, timestamp: "2024-03-04T19:27:53.149811", cot: DsCot.inf),
'/123': DsDataPoint<bool>(type: DsDataType.bool, name: DsPointName('/123'), value: true, status: DsStatus.ok, timestamp: "2024-03-04T19:28:18.812448", cot: DsCot.inf),
},
{
'point1': DsDataPoint<double>(type: DsDataType.real, name: DsPointName('/test/point1'), value: 474.20942, status: DsStatus.ok, timestamp: "2024-03-04T19:28:42.201794", cot: DsCot.inf),
'point2': DsDataPoint<int>(type: DsDataType.integer, name: DsPointName('/test/point2'), value: 342134, status: DsStatus.ok, timestamp: "2024-03-04T19:28:58.117634", cot: DsCot.inf),
'point3': DsDataPoint<bool>(type: DsDataType.bool, name: DsPointName('/test/point3'), value: false, status: DsStatus.ok, timestamp: "2024-03-04T19:29:20.274314", cot: DsCot.inf),
'/point1': DsDataPoint<double>(type: DsDataType.real, name: DsPointName('/test/point1'), value: 474.20942, status: DsStatus.ok, timestamp: "2024-03-04T19:28:42.201794", cot: DsCot.inf),
'/point2': DsDataPoint<int>(type: DsDataType.integer, name: DsPointName('/test/point2'), value: 342134, status: DsStatus.ok, timestamp: "2024-03-04T19:28:58.117634", cot: DsCot.inf),
'/point3': DsDataPoint<bool>(type: DsDataType.bool, name: DsPointName('/test/point3'), value: false, status: DsStatus.ok, timestamp: "2024-03-04T19:29:20.274314", cot: DsCot.inf),
},
];
test('getAll() returns initial cache from existing file', () async {
Expand All @@ -52,7 +58,7 @@ void main() {
cacheFile: FakeDsCacheFile(initialCache),
);
for(var i=0; i<cacheEntries.length; i++) {
final pointName = cacheEntries[i].key;
final pointName = DsPointName(cacheEntries[i].key);
final point = cacheEntries[i].value;
final option = await cache.get(pointName);
expect(option, isA<Some>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() {
final cache = DsClientMemoryCache();
for(final point in testPoints) {
await cache.add(point);
final option = await cache.get(point.name.name);
final option = await cache.get(point.name);
expect(option, isA<Some>());
final receivedPoint = (option as Some<DsDataPoint>).value;
expect(receivedPoint, equals(point));
Expand Down Expand Up @@ -55,7 +55,7 @@ void main() {
DsDataPoint(type: DsDataType.integer, name: DsPointName('/test/point1'), value: 342134, status: DsStatus.ok, timestamp: "2024-03-04T19:25:29.228612", cot: DsCot.inf),
DsDataPoint(type: DsDataType.bool, name: DsPointName('/test/point1'), value: false, status: DsStatus.timeInvalid, timestamp: "2024-03-04T19:25:29.228612", cot: DsCot.inf),
];
const pointName = 'point1';
final pointName = DsPointName('/test/point1');
final cache = DsClientMemoryCache();
DsDataPoint oldPoint = uniqueTestPoints[0];
await cache.add(oldPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,30 @@ void main() {
expect(await cache.getAll(), equals(const <DsDataPoint>[]));
});
test('get(pointName) returns null if no initial cache provided', () async {
final testPointNames = ['Winch2.EncoderBR1', 'ConstantTension.Active', 'HPA.LowNiroPressure', 'HPU.HighPressure', 'Winch1.Overload'];
final testPointNames = [
DsPointName('/Winch2.EncoderBR1'),
DsPointName('/ConstantTension.Active'),
DsPointName('/HPA.LowNiroPressure'),
DsPointName('/HPU.HighPressure'),
DsPointName('/Winch1.Overload'),
];
final cache = DsClientMemoryCache();
for(final pointName in testPointNames) {
expect(await cache.get(pointName), isA<None>());
}
});
final initialCaches = [
{
'': DsDataPoint(type: DsDataType.bool, name: DsPointName('/'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/': DsDataPoint(type: DsDataType.bool, name: DsPointName('/'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
},
{
'abc': DsDataPoint(type: DsDataType.bool, name: DsPointName('/'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'123': DsDataPoint(type: DsDataType.bool, name: DsPointName('/'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/abc': DsDataPoint(type: DsDataType.bool, name: DsPointName('/abc'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/123': DsDataPoint(type: DsDataType.bool, name: DsPointName('/123'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
},
{
'point1': DsDataPoint(type: DsDataType.real, name: DsPointName('/test/point1'), value: 474.20942, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'point2': DsDataPoint(type: DsDataType.integer, name: DsPointName('/test/point2'), value: 342134, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'point3': DsDataPoint(type: DsDataType.bool, name: DsPointName('/test/point3'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/point1': DsDataPoint(type: DsDataType.real, name: DsPointName('/test/point1'), value: 474.20942, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/point2': DsDataPoint(type: DsDataType.integer, name: DsPointName('/test/point2'), value: 342134, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
'/point3': DsDataPoint(type: DsDataType.bool, name: DsPointName('/test/point3'), value: false, status: DsStatus.ok, timestamp: DsTimeStamp.now().toString(), cot: DsCot.inf),
},
];
test('getAll() returns provided initial cache', () async {
Expand All @@ -40,7 +46,7 @@ void main() {
final cacheEntries = initialCache.entries.toList();
final cache = DsClientMemoryCache(initialCache: initialCache);
for(var i=0; i<cacheEntries.length; i++) {
final pointName = cacheEntries[i].key;
final pointName = DsPointName(cacheEntries[i].key);
final point = cacheEntries[i].value;
final option = await cache.get(pointName);
expect(option, isA<Some>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void main() {
final receivedCommands = <String>[];
const targetCommandsStartings = [
// Command sent to server
'{"type":"bool","name":"/App/Jds/Gi","value":true,"status":0,"history":0,"alarm":0,"cot":"Req","timestamp":"',
//'{"type":"bool","name":"/App/Jds/Gi","value":true,"status":0,"history":0,"alarm":0,"cot":"Req","timestamp":"',
];
line.stream.listen((event) { return; });
// Do not remove! `Connection reset by peer` error will be thrown on group run.
Expand Down

0 comments on commit 93687b9

Please sign in to comment.