feat: Implement new Hive Database
The hive database now implements the whole API except for storing files which should be better done by the flutter_cache_manager package inside of the flutter app. All tests already run with Hive now but the Moor database is still tested too. We needed to change some wait jobs in the tests because the Hive database is not 100% in memory for the tests like Moor. For now both database implementations are equal and the developer can pick which one to use but we plan to get rid of Moor in the future.
This commit is contained in:
parent
28dc8b4ff0
commit
14ee16fe16
|
|
@ -39,3 +39,4 @@ export 'src/timeline.dart';
|
||||||
export 'src/user.dart';
|
export 'src/user.dart';
|
||||||
export 'src/database/database.dart' show Database;
|
export 'src/database/database.dart' show Database;
|
||||||
export 'src/database/database_api.dart';
|
export 'src/database/database_api.dart';
|
||||||
|
export 'src/database/hive_database.dart';
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -20,6 +20,7 @@ dependencies:
|
||||||
olm: ^2.0.0
|
olm: ^2.0.0
|
||||||
isolate: ^2.0.3
|
isolate: ^2.0.3
|
||||||
matrix_api_lite: ^0.3.3
|
matrix_api_lite: ^0.3.3
|
||||||
|
hive: ^2.0.4
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
test: ^1.15.7
|
test: ^1.15.7
|
||||||
|
|
@ -27,5 +28,5 @@ dev_dependencies:
|
||||||
moor_generator: ^4.0.0
|
moor_generator: ^4.0.0
|
||||||
build_runner: ^1.11.1
|
build_runner: ^1.11.1
|
||||||
pedantic: ^1.11.0
|
pedantic: ^1.11.0
|
||||||
dapackages: ^1.4.0
|
file: ^6.1.1
|
||||||
#flutter_test: {sdk: flutter}
|
#flutter_test: {sdk: flutter}
|
||||||
|
|
|
||||||
|
|
@ -540,7 +540,7 @@ void main() {
|
||||||
newOlmAccount: pickledOlmAccount,
|
newOlmAccount: pickledOlmAccount,
|
||||||
);
|
);
|
||||||
|
|
||||||
await Future.delayed(Duration(milliseconds: 50));
|
await Future.delayed(Duration(milliseconds: 500));
|
||||||
|
|
||||||
expect(client1.isLogged(), true);
|
expect(client1.isLogged(), true);
|
||||||
expect(client1.rooms.length, 2);
|
expect(client1.rooms.length, 2);
|
||||||
|
|
@ -552,7 +552,7 @@ void main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
await client2.init();
|
await client2.init();
|
||||||
await Future.delayed(Duration(milliseconds: 100));
|
await Future.delayed(Duration(milliseconds: 500));
|
||||||
|
|
||||||
expect(client2.isLogged(), true);
|
expect(client2.isLogged(), true);
|
||||||
expect(client2.accessToken, client1.accessToken);
|
expect(client2.accessToken, client1.accessToken);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,10 @@ import 'fake_database_native.dart';
|
||||||
void main() {
|
void main() {
|
||||||
/// All Tests related to the ChatTime
|
/// All Tests related to the ChatTime
|
||||||
group('Moor Database Test', () {
|
group('Moor Database Test', () {
|
||||||
testDatabase(getDatabase(null), 0);
|
testDatabase(getMoorDatabase(null), 0);
|
||||||
|
});
|
||||||
|
group('Hive Database Test', () {
|
||||||
|
testDatabase(getHiveDatabase(null), 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -386,6 +386,9 @@ void main() {
|
||||||
null,
|
null,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
// There is a non awaiting setInboundGroupSession call on the database
|
||||||
|
await Future.delayed(Duration(seconds: 1));
|
||||||
|
|
||||||
await matrix.dispose(closeDatabase: true);
|
await matrix.dispose(closeDatabase: true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ void main() {
|
||||||
await client1.userDeviceKeys[client2.userID].startVerification();
|
await client1.userDeviceKeys[client2.userID].startVerification();
|
||||||
expect(req1.state, KeyVerificationState.askSSSS);
|
expect(req1.state, KeyVerificationState.askSSSS);
|
||||||
await req1.openSSSS(recoveryKey: ssssKey);
|
await req1.openSSSS(recoveryKey: ssssKey);
|
||||||
await Future.delayed(Duration(milliseconds: 10));
|
await Future.delayed(Duration(seconds: 1));
|
||||||
expect(req1.state, KeyVerificationState.waitingAccept);
|
expect(req1.state, KeyVerificationState.waitingAccept);
|
||||||
|
|
||||||
await req1.cancel();
|
await req1.cancel();
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ void main() {
|
||||||
client.encryption.keyManager.setInboundGroupSession(
|
client.encryption.keyManager.setInboundGroupSession(
|
||||||
roomId, sessionId, senderKey, sessionPayload,
|
roomId, sessionId, senderKey, sessionPayload,
|
||||||
forwarded: true);
|
forwarded: true);
|
||||||
|
await Future.delayed(Duration(milliseconds: 500));
|
||||||
var dbSessions = await client.database.getInboundGroupSessionsToUpload();
|
var dbSessions = await client.database.getInboundGroupSessionsToUpload();
|
||||||
expect(dbSessions.isNotEmpty, true);
|
expect(dbSessions.isNotEmpty, true);
|
||||||
await client.encryption.keyManager.backgroundTasks();
|
await client.encryption.keyManager.backgroundTasks();
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,35 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import 'dart:io';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
|
import 'package:famedlysdk/src/database/hive_database.dart';
|
||||||
|
import 'package:file/memory.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
import 'package:moor/moor.dart';
|
import 'package:moor/moor.dart';
|
||||||
import 'package:moor/ffi.dart' as moor;
|
import 'package:moor/ffi.dart' as moor;
|
||||||
|
|
||||||
Future<Database> getDatabase(Client _) async {
|
Future<DatabaseApi> getDatabase(Client _) => getHiveDatabase(_);
|
||||||
|
|
||||||
|
Future<Database> getMoorDatabase(Client _) async {
|
||||||
moorRuntimeOptions.dontWarnAboutMultipleDatabases = true;
|
moorRuntimeOptions.dontWarnAboutMultipleDatabases = true;
|
||||||
return Database(moor.VmDatabase.memory());
|
return Database(moor.VmDatabase.memory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hiveInitialized = false;
|
||||||
|
|
||||||
|
Future<FamedlySdkHiveDatabase> getHiveDatabase(Client c) async {
|
||||||
|
if (!hiveInitialized) {
|
||||||
|
final fileSystem = MemoryFileSystem();
|
||||||
|
final testHivePath =
|
||||||
|
'${fileSystem.path}/build/.test_store/${Random().nextDouble()}';
|
||||||
|
Directory(testHivePath).createSync(recursive: true);
|
||||||
|
Hive.init(testHivePath);
|
||||||
|
hiveInitialized = true;
|
||||||
|
}
|
||||||
|
final db = FamedlySdkHiveDatabase('unit_test.${c.hashCode}');
|
||||||
|
await db.open();
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue