Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-boot-admin
Commits
44c839af
Commit
44c839af
authored
Dec 15, 2015
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit the number of stored events in journal
parent
82c8d819
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
17 deletions
+40
-17
SimpleJournaledEventStore.java
...c/boot/admin/journal/store/SimpleJournaledEventStore.java
+15
-7
SimpleJournaledEventStoreTest.java
...ot/admin/journal/store/SimpleJournaledEventStoreTest.java
+25
-10
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/journal/store/SimpleJournaledEventStore.java
View file @
44c839af
...
...
@@ -17,7 +17,7 @@ package de.codecentric.boot.admin.journal.store;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.
Collections
;
import
java.util.
LinkedList
;
import
java.util.List
;
import
de.codecentric.boot.admin.event.ClientApplicationEvent
;
...
...
@@ -28,20 +28,28 @@ import de.codecentric.boot.admin.event.ClientApplicationEvent;
* @author Johannes Stelzer
*/
public
class
SimpleJournaledEventStore
implements
JournaledEventStore
{
private
final
List
<
ClientApplicationEvent
>
store
=
new
LinkedList
<
ClientApplicationEvent
>();
private
final
List
<
ClientApplicationEvent
>
store
=
Collections
.
synchronizedList
(
new
ArrayList
<
ClientApplicationEvent
>(
1000
));
private
int
capacity
=
1_000
;
@Override
public
Collection
<
ClientApplicationEvent
>
findAll
()
{
ArrayList
<
ClientApplicationEvent
>
list
=
new
ArrayList
<>(
store
);
Collections
.
reverse
(
list
);
return
list
;
synchronized
(
this
.
store
)
{
return
new
ArrayList
<>(
store
);
}
}
@Override
public
void
store
(
ClientApplicationEvent
event
)
{
store
.
add
(
event
);
synchronized
(
this
.
store
)
{
while
(
store
.
size
()
>=
capacity
)
{
store
.
remove
(
capacity
-
1
);
}
store
.
add
(
0
,
event
);
}
}
public
void
setCapacity
(
int
capacity
)
{
this
.
capacity
=
capacity
;
}
}
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/journal/store/SimpleJournaledEventStoreTest.java
View file @
44c839af
...
...
@@ -18,10 +18,8 @@ package de.codecentric.boot.admin.journal.store;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
org.junit.Test
;
...
...
@@ -33,22 +31,39 @@ import de.codecentric.boot.admin.model.Application;
public
class
SimpleJournaledEventStoreTest
{
private
SimpleJournaledEventStore
store
=
new
SimpleJournaledEventStore
();
@Test
public
void
test_store
()
{
SimpleJournaledEventStore
store
=
new
SimpleJournaledEventStore
();
Application
application
=
Application
.
create
(
"foo"
).
withId
(
"bar"
).
build
();
List
<
ClientApplicationEvent
>
events
=
Arrays
.
asList
(
new
ClientApplicationRegisteredEvent
(
application
),
new
ClientApplicationDeregisteredEvent
(
application
));
List
<
ClientApplicationEvent
>
events
=
Arrays
.
asList
(
new
ClientApplicationRegisteredEvent
(
application
),
new
ClientApplicationDeregisteredEvent
(
application
));
for
(
ClientApplicationEvent
event
:
events
)
{
store
.
store
(
event
);
}
// Items are stored in reverse order
List
<
ClientApplicationEvent
>
reversed
=
new
ArrayList
<>(
events
);
Collections
.
reverse
(
reversed
);
assertThat
(
store
.
findAll
(),
is
(
(
Collection
<
ClientApplicationEvent
>)
Arrays
.
asList
(
events
.
get
(
1
),
events
.
get
(
0
))));
}
@Test
public
void
test_store_capacity
()
{
SimpleJournaledEventStore
store
=
new
SimpleJournaledEventStore
();
store
.
setCapacity
(
2
);
Application
application
=
Application
.
create
(
"foo"
).
withId
(
"bar"
).
build
();
List
<
ClientApplicationEvent
>
events
=
Arrays
.
asList
(
new
ClientApplicationRegisteredEvent
(
application
),
new
ClientApplicationDeregisteredEvent
(
application
),
new
ClientApplicationDeregisteredEvent
(
application
));
assertThat
(
store
.
findAll
(),
is
((
Collection
<
ClientApplicationEvent
>)
reversed
));
for
(
ClientApplicationEvent
event
:
events
)
{
store
.
store
(
event
);
}
assertThat
(
store
.
findAll
(),
is
(
(
Collection
<
ClientApplicationEvent
>)
Arrays
.
asList
(
events
.
get
(
2
),
events
.
get
(
1
))));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment