Skip to content

Commit

Permalink
feat: Changes related to notify ephemeral
Browse files Browse the repository at this point in the history
  • Loading branch information
sitaram-kalluri committed Sep 8, 2023
1 parent a1eea18 commit 05acdf2
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/at_secondary_server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 3.0.36
- fix: Implement notify ephemeral changes - Send notification with value without caching the key on receiver's secondary server
## 3.0.35
- chore: Upgraded at_persistence_secondary_server to 3.0.57 for memory optimization in commit log
- feat: APKAM keys verb implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ResourceManager {
NotifyConnectionsPool.getInstance();

int get outboundConnectionLimit => _notifyConnectionsPool.size;

set outboundConnectionLimit(int ocl) => _notifyConnectionsPool.size = ocl;

void start() {
Expand Down Expand Up @@ -201,6 +202,9 @@ class ResourceManager {
// looked at this code.
String commandBody;
commandBody = '${atNotification.notification}';
if (atNotification.atValue != null) {
commandBody = '$commandBody:${atNotification.atValue}';
}
var atMetaData = atNotification.atMetadata;
if (atMetaData != null) {
if (atNotification.atMetadata!.skeEncAlgo != null) {
Expand Down Expand Up @@ -237,7 +241,7 @@ class ResourceManager {
}
if (atMetaData.ttr != null) {
commandBody =
'ttr:${atMetaData.ttr}:ccd:${atMetaData.isCascade}:$commandBody:${atNotification.atValue}';
'ttr:${atMetaData.ttr}:ccd:${atMetaData.isCascade}:$commandBody';
}
if (atMetaData.ttb != null) {
commandBody = 'ttb:${atMetaData.ttb}:$commandBody';
Expand Down
2 changes: 1 addition & 1 deletion packages/at_secondary_server/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: at_secondary
description: Implementation of secondary server.
version: 3.0.35
version: 3.0.36
repository: https://github.com/atsign-foundation/at_server
homepage: https://www.example.com
publish_to: none
Expand Down
239 changes: 237 additions & 2 deletions tests/at_end2end_test/test/notify_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void main() {
response = await sh1.read();
print('notify list verb response : $response');
expect(response,
contains('"key":"$atSign_1:contact-no$atSign_2","value":null'));
contains('"key":"$atSign_1:contact-no$atSign_2","value":"$value'));
});

test('notify verb without messageType', () async {
Expand Down Expand Up @@ -200,7 +200,7 @@ void main() {
expect(
response,
contains(
'"key":"$atSign_2:email$atSign_1","value":"null","operation":"delete"'));
'"key":"$atSign_2:email$atSign_1","value":null,"operation":"delete"'));
});

test('notify verb without giving message type value', () async {
Expand Down Expand Up @@ -700,6 +700,241 @@ void main() {
expect(decodedResponse['metaData']['skeEncAlgo'], null);
}
});

group('A group of tests related to notify ephemeral', () {
test(
'notify verb without ttr for messageType-key and operation type - update and with value',
() async {
// The notify ephemeral changes are not into Canary and production.
// So, no point in running against and Canary and Prod servers.`
if (atSign1ServerVersion < Version(3, 0, 36)) {
return;
}
/// NOTIFY VERB
var value = 'testingvalue';
await sh2.writeCommand(
'notify:update:messageType:key:$atSign_1:testkey$atSign_2:$value');
String response = await sh2.read();
print('notify verb response : $response');
assert((!response.contains('Invalid syntax')) &&
(!response.contains('null')));
String notificationId = response.replaceAll('data:', '');

// notify status
response = await getNotifyStatus(sh2, notificationId,
returnWhenStatusIn: ['delivered'], timeOutMillis: 15000);
print('notify status response : $response');
assert(response.contains('data:delivered'));

///notify:list verb
await sh1.writeCommand('notify:list');
response = await sh1.read();
print('notify list verb response : $response');
expect(
response,
contains(
'"key":"$atSign_1:testkey$atSign_2","value":"$value","operation":"update"'));
});

test('notify verb without ttr and without value for operation type update',
() async {
// The notify ephemeral changes are not into Canary and production.
// So, no point in running against and Canary and Prod servers.`
if (atSign1ServerVersion < Version(3, 0, 36)) {
return;
}

/// NOTIFY VERB
await sh2.writeCommand('notify:update:$atSign_1:nottrkey$atSign_2');
String response = await sh2.read();
print('notify verb response : $response');
assert((!response.contains('Invalid syntax')) &&
(!response.contains('null')));
String notificationId = response.replaceAll('data:', '');

// notify status
response = await getNotifyStatus(sh2, notificationId,
returnWhenStatusIn: ['delivered'], timeOutMillis: 15000);
print('notify status response : $response');
assert(response.contains('data:delivered'));

///notify:list verb
await sh1.writeCommand('notify:list');
response = await sh1.read();
print('notify list verb response : $response');
expect(
response,
contains(
'"key":"$atSign_1:nottrkey$atSign_2","value":null,"operation":"update"'));
});

test(
'notify verb without ttr for messageType-text and operation type - update',
() async {
// The notify ephemeral changes are not into Canary and production.
// So, no point in running against and Canary and Prod servers.`
if (atSign1ServerVersion < Version(3, 0, 36)) {
return;
}

/// NOTIFY VERB
await sh2.writeCommand(
'notify:update:messageType:text:$atSign_1:hello_world$atSign_2');
String response = await sh2.read();
print('notify verb response : $response');
assert((!response.contains('Invalid syntax')) &&
(!response.contains('null')));
String notificationId = response.replaceAll('data:', '');

// notify status
response = await getNotifyStatus(sh2, notificationId,
returnWhenStatusIn: ['delivered'], timeOutMillis: 15000);
print('notify status response : $response');
assert(response.contains('data:delivered'));

///notify:list verb
await sh1.writeCommand('notify:list');
response = await sh1.read();
print('notify list verb response : $response');
expect(
response,
contains(
'"key":"$atSign_1:hello_world","value":null,"operation":"update"'));
});

test(
'notify verb without ttr for messageType-text and operation type - delete',
() async {
// The notify ephemeral changes are not into Canary and production.
// So, no point in running against and Canary and Prod servers.`
if (atSign1ServerVersion < Version(3, 0, 36)) {
return;
}

/// NOTIFY VERB
await sh2.writeCommand(
'notify:delete:messageType:text:$atSign_1:hello_world$atSign_2');
String response = await sh2.read();
print('notify verb response : $response');
assert((!response.contains('Invalid syntax')) &&
(!response.contains('null')));
String notificationId = response.replaceAll('data:', '');

// notify status
response = await getNotifyStatus(sh2, notificationId,
returnWhenStatusIn: ['delivered'], timeOutMillis: 15000);
print('notify status response : $response');
assert(response.contains('data:delivered'));

///notify:list verb
await sh1.writeCommand('notify:list');
response = await sh1.read();
print('notify list verb response : $response');
expect(
response,
contains(
'"key":"$atSign_1:hello_world","value":null,"operation":"delete"'));
});

test(
'notify verb without ttr and without value for operation type update (self notification)',
() async {
// The notify ephemeral changes are not into Canary and production.
// So, no point in running against and Canary and Prod servers.`
if (atSign1ServerVersion < Version(3, 0, 36)) {
return;
}

/// NOTIFY VERB
await sh2.writeCommand('notify:update:$atSign_2:nottrkey$atSign_2');
String response = await sh2.read();
print('notify verb response : $response');
assert((!response.contains('Invalid syntax')) &&
(!response.contains('null')));
String notificationId = response.replaceAll('data:', '');

// notify status
response = await getNotifyStatus(sh2, notificationId,
returnWhenStatusIn: ['delivered'], timeOutMillis: 15000);
print('notify status response : $response');
assert(response.contains('data:delivered'));

///notify:list verb
await sh2.writeCommand('notify:list');
response = await sh2.read();
print('notify list verb response : $response');
expect(
response,
contains(
'"key":"$atSign_2:nottrkey$atSign_2","value":null,"operation":"update"'));
});

test(
'notify verb without ttr and with value for operation type update (self notification)',
() async {
// The notify ephemeral changes are not into Canary and production.
// So, no point in running against and Canary and Prod servers.`
if (atSign1ServerVersion < Version(3, 0, 36)) {
return;
}

/// NOTIFY VERB
var value = 'no-ttr';
await sh2
.writeCommand('notify:update:$atSign_2:nottrkey$atSign_2:$value');
String response = await sh2.read();
print('notify verb response : $response');
assert((!response.contains('Invalid syntax')) &&
(!response.contains('null')));
String notificationId = response.replaceAll('data:', '');

// notify status
response = await getNotifyStatus(sh2, notificationId,
returnWhenStatusIn: ['delivered'], timeOutMillis: 15000);
print('notify status response : $response');
assert(response.contains('data:delivered'));

///notify:list verb
await sh2.writeCommand('notify:list');
response = await sh2.read();
print('notify list verb response : $response');
expect(
response,
contains(
'"key":"$atSign_2:nottrkey$atSign_2","value":"$value","operation":"update"'));
});

test('notify verb without ttr for operation type delete', () async {
// The notify ephemeral changes are not into Canary and production.
// So, no point in running against and Canary and Prod servers.`
if (atSign1ServerVersion < Version(3, 0, 36)) {
return;
}

/// NOTIFY VERB
await sh2.writeCommand('notify:delete:$atSign_1:twitter-id$atSign_2');
String response = await sh2.read();
print('notify verb response : $response');
assert((!response.contains('Invalid syntax')) &&
(!response.contains('null')));
String notificationId = response.replaceAll('data:', '');

// notify status
response = await getNotifyStatus(sh2, notificationId,
returnWhenStatusIn: ['delivered'], timeOutMillis: 15000);
print('notify status response : $response');
assert(response.contains('data:delivered'));

///notify:list verb
await sh1.writeCommand('notify:list');
response = await sh1.read();
print('notify list verb response : $response');
expect(
response,
contains(
'"key":"$atSign_1:twitter-id$atSign_2","value":null,"operation":"delete"'));
});
});
}

// get notify status
Expand Down

0 comments on commit 05acdf2

Please sign in to comment.