Skip to content

Commit 80dee6b

Browse files
committed
both unit and integration tests passing
1 parent 5a63edd commit 80dee6b

File tree

7 files changed

+80
-40
lines changed

7 files changed

+80
-40
lines changed

client/load/src/load/integration.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@
8787
(if (not (= inbound-occurred-from-message now))
8888
(report-error "error in occurred logic part of social broadcast"))))
8989
(Thread/sleep 10000)
90-
(if (not (>= (count (doall (filter (fn [sender] (= sender from-id)) (elastic/search "test")))) 1))
91-
(report-error (str "Error in keyword search. Cannot find sender " from-id " in " (json/write-str (elastic/search "test")))))
9290
(let [from-sender (str "/participant/" (.toString from-id))
9391
search-results (:results (core/test-search "test"))]
92+
(if (not (>= (count (doall (filter (fn [sender] (or (= sender from-id) (= sender from-sender))) (elastic/search "test")))) 1))
93+
(report-error (str "Error in keyword search. Cannot find sender " from-id " in " (json/write-str (elastic/search "test")))))
9494
(if (not (>= (count (doall (filter (fn [sender] (= from-sender sender)) search-results))) 1))
9595
(report-error (str "Error in keyword search. Cannot find sender " from-sender " in " search-results)))))
9696

server/feed16/src/elasticsearch.module.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ import { SearchService } from './search.service';
1212
maxRetries: 10,
1313
requestTimeout: 60000,
1414
pingTimeout: 60000,
15-
sniffOnStart: true,
16-
auth: {
17-
username: 'elastic',
18-
password: 'elastic',
19-
},
15+
sniffOnStart: false,
16+
sniffInterval: false,
2017
}),
2118
}),
2219
],

server/feed16/src/participant/participant.controller.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('ParticipantApiController', () => {
2525
let inboundSaved: number = 0;
2626
let outboundSaved: number = 0;
2727
const nowAsDate: Date = new Date();
28+
const nowAsDateOnly: string = nowAsDate.toISOString().slice(0, 10)
2829

2930
beforeEach(async () => {
3031
const pe: ParticipantEntity = new ParticipantEntity();
@@ -120,12 +121,12 @@ describe('ParticipantApiController', () => {
120121

121122
describe('participant', () => {
122123
it('fetch should return mocked entity', async () => {
123-
const p: Participant = new Participant(1, 'Hello World!');
124+
const p: Participant = new Participant(1, 'Hello World!', '/participant/1');
124125
const t: Participant | undefined = await appController?.getParticipant(1);
125126
expect(t).toStrictEqual(p);
126127
});
127128
it('add should call underlying repository add', async () => {
128-
const p: Participant = new Participant(1, 'Hello World!');
129+
const p: Participant = new Participant(1, 'Hello World!', '/participant/1');
129130
const t: Participant | undefined = await appController?.addParticipant(p);
130131
expect(participantSaved).toBeGreaterThan(0);
131132
expect(t).toStrictEqual(p);
@@ -139,8 +140,8 @@ describe('ParticipantApiController', () => {
139140
expect(t?.[0].to).toBe('/participant/2');
140141
});
141142
it('add should call underlying repository add', async () => {
142-
const p1: Participant = new Participant(1, 'Hello World!');
143-
const p2: Participant = new Participant(2, 'foo bar');
143+
const p1: Participant = new Participant(1, 'Hello World!', '/participant/1');
144+
const p2: Participant = new Participant(2, 'foo bar', '/participant/2');
144145
const f: Friend = new Friend(1, p1.link, p2.link);
145146
const t: Friend | undefined = await appController?.addFriend(1, f);
146147
expect(friendSaved).toBeGreaterThan(0);
@@ -153,7 +154,7 @@ describe('ParticipantApiController', () => {
153154
expect(t?.length).toBe(1);
154155
expect(t?.[0].from).toBe('/participant/1');
155156
expect(t?.[0].to).toBe('/participant/2');
156-
expect(t?.[0].occurred).toStrictEqual(nowAsDate);
157+
expect(t?.[0].occurred).toStrictEqual(nowAsDateOnly);
157158
expect(t?.[0].subject).toBe('test subject');
158159
expect(t?.[0].story).toBe('test story');
159160
});
@@ -168,7 +169,7 @@ describe('ParticipantApiController', () => {
168169
expect(t?.[0].story).toBe('test story');
169170
});
170171
it('add should call underlying repository add', async () => {
171-
const p1: Participant = new Participant(1, 'Hello World!');
172+
const p1: Participant = new Participant(1, 'Hello World!', '/participant/1');
172173
const o: Outbound = new Outbound(
173174
p1.link,
174175
nowAsDate,

server/feed16/src/participant/participant.controller.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Controller, Get, Post, Body, Param } from '@nestjs/common';
1+
import { Controller, Get, Post, HttpCode, HttpStatus, Body, Param } from '@nestjs/common';
22
import {
33
ParticipantService,
44
FriendModel,
@@ -9,26 +9,24 @@ import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
99

1010
export class Friend {
1111
constructor(
12-
public readonly id: number,
12+
public readonly id: number = 0,
1313
public readonly from: string,
1414
public readonly to: string,
1515
) {}
1616
}
1717

1818
export class Participant {
1919
constructor(
20-
public readonly id: number,
20+
public readonly id: number = 0,
2121
public readonly name: string,
22+
public readonly link: string,
2223
) {}
23-
24-
accessor link = `/participant/${this.id}`;
2524
}
26-
2725
export class Inbound {
2826
constructor(
2927
public readonly from: string,
3028
public readonly to: string,
31-
public readonly occurred: Date,
29+
public readonly occurred: string,
3230
public readonly subject: string,
3331
public readonly story: string,
3432
) {}
@@ -49,6 +47,7 @@ export class ParticipantApiController {
4947
constructor(private readonly participantApiService: ParticipantService) {}
5048

5149
@Post(':id/friends')
50+
@HttpCode(HttpStatus.OK)
5251
@ApiOperation({ summary: 'Create a new friendship' })
5352
@ApiResponse({
5453
status: 200,
@@ -59,18 +58,21 @@ export class ParticipantApiController {
5958
@Param('id') id: number,
6059
@Body() body: Friend,
6160
): Promise<Friend> {
61+
const fpm = new ParticipantModel(parseInt(body.from.split('/').pop() as string), '');
62+
const tpm = new ParticipantModel(parseInt(body.to.split('/').pop() as string), '');
6263
const fm = new FriendModel(
6364
body.id,
64-
new ParticipantModel(parseInt(body.from.split('/').pop() as string), ''),
65-
new ParticipantModel(parseInt(body.to.split('/').pop() as string), ''),
65+
fpm,
66+
tpm,
6667
);
6768
const saved = await this.participantApiService.addFriend(id, fm);
68-
const from = new Participant(saved.from.id, '');
69-
const to = new Participant(saved.to.id, '');
69+
const from = new Participant(saved.from.id, '', fpm.link);
70+
const to = new Participant(saved.to.id, '', tpm.link);
7071
return new Friend(saved.id, from.link, to.link);
7172
}
7273

7374
@Post(':id/outbound')
75+
@HttpCode(HttpStatus.OK)
7476
@ApiOperation({ summary: 'Create a participant news item' })
7577
@ApiResponse({
7678
status: 200,
@@ -92,6 +94,7 @@ export class ParticipantApiController {
9294
}
9395

9496
@Post()
97+
@HttpCode(HttpStatus.OK)
9598
@ApiOperation({ summary: 'Create a new participant' })
9699
@ApiResponse({
97100
status: 200,
@@ -101,7 +104,7 @@ export class ParticipantApiController {
101104
public async addParticipant(@Body() body: Participant): Promise<Participant> {
102105
const pm = new ParticipantModel(body.id, body.name);
103106
const saved = await this.participantApiService.addParticipant(pm);
104-
return new Participant(saved.id, saved.moniker);
107+
return new Participant(saved.id, saved.name, saved.link);
105108
}
106109

107110
@Get(':id/friends')
@@ -116,8 +119,8 @@ export class ParticipantApiController {
116119
public async getFriends(@Param('id') id: number): Promise<Friend[]> {
117120
const rv = await this.participantApiService.getFriends(id);
118121
return rv.map((f) => {
119-
const from = new Participant(f.from.id, '');
120-
const to = new Participant(f.to.id, '');
122+
const from = new Participant(f.from.id, '', f.from.link);
123+
const to = new Participant(f.to.id, '', f.to.link);
121124
return new Friend(f.id, from.link, to.link);
122125
});
123126
}
@@ -134,9 +137,9 @@ export class ParticipantApiController {
134137
public async getInbound(@Param('id') id: number): Promise<Inbound[]> {
135138
const ib = await this.participantApiService.getInbound(id);
136139
return ib.map((i) => {
137-
const from = new Participant(i.from.id, '');
138-
const to = new Participant(i.to.id, '');
139-
return new Inbound(from.link, to.link, i.occurred, i.subject, i.story);
140+
const from = new Participant(i.from.id, '', '/participant/' + `${i.from.id}`);
141+
const to = new Participant(i.to.id, '', '/participant/' + `${i.to.id}`);
142+
return new Inbound(from.link, to.link, i.occurred.toISOString().slice(0, 10), i.subject, i.story);
140143
});
141144
}
142145

@@ -165,6 +168,6 @@ export class ParticipantApiController {
165168
})
166169
public async getParticipant(@Param('id') id: number): Promise<Participant> {
167170
const pm = await this.participantApiService.getParticipant(id);
168-
return new Participant(pm.id, pm.moniker);
171+
return new Participant(pm.id, pm.name, pm.link);
169172
}
170173
}

server/feed16/src/participant/participant.service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class InboundService extends CassandraRepository {
107107
export class ParticipantModel {
108108
constructor(
109109
public readonly id: number,
110-
public readonly moniker: string,
110+
public readonly name: string,
111111
) {}
112112
accessor link = `/participant/${this.id}`;
113113
public toString(): string {
@@ -141,7 +141,7 @@ export class ParticipantService {
141141

142142
async addParticipant(body: ParticipantModel): Promise<ParticipantModel> {
143143
const participant = new Participant();
144-
participant.moniker = body.moniker;
144+
participant.moniker = body.name;
145145
const savedParticipant = await this.participantRepository.save(participant);
146146
return new ParticipantModel(
147147
savedParticipant.participantId,
@@ -154,7 +154,7 @@ export class ParticipantService {
154154
}
155155

156156
async getParticipant(id: number): Promise<ParticipantModel> {
157-
const cacheKey = `participant:${id}`;
157+
const cacheKey = 'Participant::' + `${id}`;
158158
const cachedParticipant =
159159
await this.cacheManager.get<ParticipantModel>(cacheKey);
160160
if (cachedParticipant) {
@@ -179,12 +179,13 @@ export class ParticipantService {
179179
friend.fromParticipantId = id;
180180
friend.toParticipantId = body.to.id;
181181
const savedFriend = await this.friendRepository.save(friend);
182-
this.cacheManager.del(`friend:${id}`);
182+
this.cacheManager.del('Friend::' + `${id}`);
183+
this.cacheManager.del('Friend::' + `${body.to.id}`);
183184
return new FriendModel(savedFriend.friendsId, body.from, body.to);
184185
}
185186

186187
async getFriends(id: number): Promise<FriendModel[]> {
187-
const cacheKey = `friend:${id}`;
188+
const cacheKey = 'Friend::' + `${id}`;
188189
const cachedFriends = await this.cacheManager.get<FriendModel[]>(cacheKey);
189190
if (cachedFriends) {
190191
return cachedFriends;

server/helm/templates/elasticsearch.yaml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,49 @@ spec:
3232
name: elasticsearch
3333
spec:
3434
containers:
35-
- env:
36-
image: "elasticsearch:{{ .Values.elasticSearchVersion }}"
37-
name: elasticsearch
35+
- name: elasticsearch
3836
ports:
3937
- containerPort: 9200
4038
hostIP: 127.0.0.1
39+
{{- if hasPrefix "8." .Values.elasticSearchVersion }}
40+
image: "docker.elastic.co/elasticsearch/elasticsearch:{{ .Values.elasticSearchVersion }}"
41+
resources:
42+
limits:
43+
memory: 1Gi
44+
env:
45+
- name: "ES_SETTING_NODE_STORE_ALLOW__MMAP"
46+
value: "false"
47+
- name: "ES_SETTING_XPACK_SECURITY_ENABLED"
48+
value: "false"
49+
- name: "ES_SETTING_DISCOVERY_TYPE"
50+
value: "single-node"
51+
lifecycle:
52+
postStart:
53+
exec:
54+
command:
55+
- "sh"
56+
- "-c"
57+
- |
58+
S=$(curl http://localhost:9200/_cat/health | grep green | wc -l)
59+
until [ $S -eq 1 ]
60+
do
61+
sleep 20
62+
S=$(curl http://localhost:9200/_cat/health | grep green | wc -l)
63+
done
64+
curl -X PUT http://localhost:9200/feed -H 'Content-Type: application/json' -d '{
65+
"settings" : {
66+
"number_of_shards" : 1
67+
},
68+
"mappings" : {
69+
"properties" : {
70+
"id" : { "type" : "keyword", "index" : false },
71+
"sender" : { "type" : "keyword", "index" : false },
72+
"story" : { "type" : "text", "index" : true }
73+
}
74+
}
75+
}'
76+
{{- else }}
77+
image: "elasticsearch:{{ .Values.elasticSearchVersion }}"
4178
lifecycle:
4279
postStart:
4380
exec:
@@ -65,4 +102,5 @@ spec:
65102
}
66103
}
67104
}'
105+
{{- end }}
68106
restartPolicy: Always

server/helm/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mysqlVersion: "5.7"
22
redisVersion: "3.2"
33
cassandraVersion: "2.2"
4-
elasticSearchVersion: "2.4"
4+
elasticSearchVersion: "8.15.1"
55
loadTest: false
66
useIngress: false
77
gui: false

0 commit comments

Comments
 (0)