mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-08-03 03:36:23 -04:00
tabledb array work
This commit is contained in:
parent
83c8715742
commit
5d89de9bfe
45 changed files with 3022 additions and 1035 deletions
|
@ -7,6 +7,7 @@ import 'fixtures/fixtures.dart';
|
|||
import 'test_dht_log.dart';
|
||||
import 'test_dht_record_pool.dart';
|
||||
import 'test_dht_short_array.dart';
|
||||
import 'test_table_db_array.dart';
|
||||
|
||||
void main() {
|
||||
final startTime = DateTime.now();
|
||||
|
@ -34,6 +35,17 @@ void main() {
|
|||
setUpAll(veilidFixture.attach);
|
||||
tearDownAll(veilidFixture.detach);
|
||||
|
||||
group('TableDB Tests', () {
|
||||
group('TableDBArray Tests', () {
|
||||
test('create TableDBArray', makeTestTableDBArrayCreateDelete());
|
||||
test(
|
||||
timeout: const Timeout(Duration(seconds: 480)),
|
||||
'add/truncate TableDBArray',
|
||||
makeTestDHTLogAddTruncate(),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('DHT Support Tests', () {
|
||||
setUpAll(updateProcessorFixture.setUp);
|
||||
setUpAll(tickerFixture.setUp);
|
||||
|
|
|
@ -64,8 +64,7 @@ Future<void> Function() makeTestDHTLogAddTruncate({required int stride}) =>
|
|||
const chunk = 25;
|
||||
for (var n = 0; n < dataset.length; n += chunk) {
|
||||
print('$n-${n + chunk - 1} ');
|
||||
final success =
|
||||
await w.tryAppendItems(dataset.sublist(n, n + chunk));
|
||||
final success = await w.tryAddItems(dataset.sublist(n, n + chunk));
|
||||
expect(success, isTrue);
|
||||
}
|
||||
});
|
||||
|
@ -94,7 +93,7 @@ Future<void> Function() makeTestDHTLogAddTruncate({required int stride}) =>
|
|||
}
|
||||
print('truncate\n');
|
||||
{
|
||||
await dlog.operateAppend((w) async => w.truncate(5));
|
||||
await dlog.operateAppend((w) async => w.truncate(w.length - 5));
|
||||
}
|
||||
{
|
||||
final dataset6 = await dlog
|
||||
|
@ -103,7 +102,7 @@ Future<void> Function() makeTestDHTLogAddTruncate({required int stride}) =>
|
|||
}
|
||||
print('truncate 2\n');
|
||||
{
|
||||
await dlog.operateAppend((w) async => w.truncate(251));
|
||||
await dlog.operateAppend((w) async => w.truncate(w.length - 251));
|
||||
}
|
||||
{
|
||||
final dataset7 = await dlog
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
Future<void> Function() makeTestTableDBArrayCreateDelete() => () async {
|
||||
// Close before delete
|
||||
{
|
||||
final arr = await TableDBArray(
|
||||
table: 'test', crypto: const VeilidCryptoPublic());
|
||||
|
||||
expect(await arr.operate((r) async => r.length), isZero);
|
||||
expect(arr.isOpen, isTrue);
|
||||
await arr.close();
|
||||
expect(arr.isOpen, isFalse);
|
||||
await arr.delete();
|
||||
// Operate should fail
|
||||
await expectLater(() async => arr.operate((r) async => r.length),
|
||||
throwsA(isA<StateError>()));
|
||||
}
|
||||
|
||||
// Close after delete
|
||||
{
|
||||
final arr = await DHTShortArray.create(
|
||||
debugName: 'sa_create_delete 2 stride $stride', stride: stride);
|
||||
await arr.delete();
|
||||
// Operate should still succeed because things aren't closed
|
||||
expect(await arr.operate((r) async => r.length), isZero);
|
||||
await arr.close();
|
||||
// Operate should fail
|
||||
await expectLater(() async => arr.operate((r) async => r.length),
|
||||
throwsA(isA<StateError>()));
|
||||
}
|
||||
|
||||
// Close after delete multiple
|
||||
// Okay to request delete multiple times before close
|
||||
{
|
||||
final arr = await DHTShortArray.create(
|
||||
debugName: 'sa_create_delete 3 stride $stride', stride: stride);
|
||||
await arr.delete();
|
||||
await arr.delete();
|
||||
// Operate should still succeed because things aren't closed
|
||||
expect(await arr.operate((r) async => r.length), isZero);
|
||||
await arr.close();
|
||||
await expectLater(() async => arr.close(), throwsA(isA<StateError>()));
|
||||
// Operate should fail
|
||||
await expectLater(() async => arr.operate((r) async => r.length),
|
||||
throwsA(isA<StateError>()));
|
||||
}
|
||||
};
|
||||
|
||||
Future<void> Function() makeTestTableDBArrayAdd({required int stride}) =>
|
||||
() async {
|
||||
final arr = await DHTShortArray.create(
|
||||
debugName: 'sa_add 1 stride $stride', stride: stride);
|
||||
|
||||
final dataset = Iterable<int>.generate(256)
|
||||
.map((n) => utf8.encode('elem $n'))
|
||||
.toList();
|
||||
|
||||
print('adding singles\n');
|
||||
{
|
||||
final res = await arr.operateWrite((w) async {
|
||||
for (var n = 4; n < 8; n++) {
|
||||
print('$n ');
|
||||
final success = await w.tryAddItem(dataset[n]);
|
||||
expect(success, isTrue);
|
||||
}
|
||||
});
|
||||
expect(res, isNull);
|
||||
}
|
||||
|
||||
print('adding batch\n');
|
||||
{
|
||||
final res = await arr.operateWrite((w) async {
|
||||
print('${dataset.length ~/ 2}-${dataset.length}');
|
||||
final success = await w.tryAddItems(
|
||||
dataset.sublist(dataset.length ~/ 2, dataset.length));
|
||||
expect(success, isTrue);
|
||||
});
|
||||
expect(res, isNull);
|
||||
}
|
||||
|
||||
print('inserting singles\n');
|
||||
{
|
||||
final res = await arr.operateWrite((w) async {
|
||||
for (var n = 0; n < 4; n++) {
|
||||
print('$n ');
|
||||
final success = await w.tryInsertItem(n, dataset[n]);
|
||||
expect(success, isTrue);
|
||||
}
|
||||
});
|
||||
expect(res, isNull);
|
||||
}
|
||||
|
||||
print('inserting batch\n');
|
||||
{
|
||||
final res = await arr.operateWrite((w) async {
|
||||
print('8-${dataset.length ~/ 2}');
|
||||
final success = await w.tryInsertItems(
|
||||
8, dataset.sublist(8, dataset.length ~/ 2));
|
||||
expect(success, isTrue);
|
||||
});
|
||||
expect(res, isNull);
|
||||
}
|
||||
|
||||
//print('get all\n');
|
||||
{
|
||||
final dataset2 = await arr.operate((r) async => r.getItemRange(0));
|
||||
expect(dataset2, equals(dataset));
|
||||
}
|
||||
{
|
||||
final dataset3 =
|
||||
await arr.operate((r) async => r.getItemRange(64, length: 128));
|
||||
expect(dataset3, equals(dataset.sublist(64, 64 + 128)));
|
||||
}
|
||||
|
||||
//print('clear\n');
|
||||
{
|
||||
await arr.operateWriteEventual((w) async {
|
||||
await w.clear();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
//print('get all\n');
|
||||
{
|
||||
final dataset4 = await arr.operate((r) async => r.getItemRange(0));
|
||||
expect(dataset4, isEmpty);
|
||||
}
|
||||
|
||||
await arr.delete();
|
||||
await arr.close();
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue