@@ -66,8 +66,10 @@ describe("partitioning adapter", () => {
66
66
it ( "verify partioning adapter with paging mode enabled works" , ( done ) => {
67
67
const mem = new LokiMemoryAdapter ( ) ;
68
68
69
- // we will use an exceptionally low page size (128bytes) to test with small dataset
70
- const adapter = new LokiPartitioningAdapter ( mem , { paging : true , pageSize : 128 } ) ;
69
+ // we will use an exceptionally low page size (64bytes) to test with small dataset
70
+ // every object will serialize to over 64bytes so that is not a hard limit but when
71
+ // we exceed that we will stop adding to page (so for this test 1 doc per page)
72
+ const adapter = new LokiPartitioningAdapter ( mem , { paging : true , pageSize : 64 } ) ;
71
73
72
74
const db = new Loki ( "sandbox.db" ) ;
73
75
let db2 ;
@@ -87,15 +89,19 @@ describe("partitioning adapter", () => {
87
89
// for purposes of our memory adapter it is pretty much synchronous
88
90
db . saveDatabase ( ) . then ( ( ) => {
89
91
// should have partitioned the data
90
- expect ( Object . keys ( mem . hashStore ) . length ) . toEqual ( 4 ) ;
92
+ expect ( Object . keys ( mem . hashStore ) . length ) . toEqual ( 6 ) ;
91
93
expect ( mem . hashStore . hasOwnProperty ( "sandbox.db" ) ) . toEqual ( true ) ;
92
94
expect ( mem . hashStore . hasOwnProperty ( "sandbox.db.0.0" ) ) . toEqual ( true ) ;
93
95
expect ( mem . hashStore . hasOwnProperty ( "sandbox.db.0.1" ) ) . toEqual ( true ) ;
96
+ expect ( mem . hashStore . hasOwnProperty ( "sandbox.db.0.2" ) ) . toEqual ( true ) ;
97
+ expect ( mem . hashStore . hasOwnProperty ( "sandbox.db.0.3" ) ) . toEqual ( true ) ;
94
98
expect ( mem . hashStore . hasOwnProperty ( "sandbox.db.1.0" ) ) . toEqual ( true ) ;
95
99
// all partitions should have been saved once each
96
100
expect ( mem . hashStore [ "sandbox.db" ] . savecount ) . toEqual ( 1 ) ;
97
101
expect ( mem . hashStore [ "sandbox.db.0.0" ] . savecount ) . toEqual ( 1 ) ;
98
102
expect ( mem . hashStore [ "sandbox.db.0.1" ] . savecount ) . toEqual ( 1 ) ;
103
+ expect ( mem . hashStore [ "sandbox.db.0.2" ] . savecount ) . toEqual ( 1 ) ;
104
+ expect ( mem . hashStore [ "sandbox.db.0.3" ] . savecount ) . toEqual ( 1 ) ;
99
105
expect ( mem . hashStore [ "sandbox.db.1.0" ] . savecount ) . toEqual ( 1 ) ;
100
106
101
107
// so let's go ahead and update one of our collections to make it dirty
@@ -109,7 +115,8 @@ describe("partitioning adapter", () => {
109
115
expect ( mem . hashStore [ "sandbox.db" ] . savecount ) . toEqual ( 2 ) ;
110
116
// we didn't change this
111
117
expect ( mem . hashStore [ "sandbox.db.0.0" ] . savecount ) . toEqual ( 1 ) ;
112
- expect ( mem . hashStore [ "sandbox.db.0.0" ] . savecount ) . toEqual ( 1 ) ;
118
+ expect ( mem . hashStore [ "sandbox.db.0.2" ] . savecount ) . toEqual ( 1 ) ;
119
+ expect ( mem . hashStore [ "sandbox.db.0.3" ] . savecount ) . toEqual ( 1 ) ;
113
120
// we updated this collection so it should have been saved again
114
121
expect ( mem . hashStore [ "sandbox.db.1.0" ] . savecount ) . toEqual ( 2 ) ;
115
122
@@ -121,7 +128,9 @@ describe("partitioning adapter", () => {
121
128
} ) . then ( ( ) => {
122
129
expect ( mem . hashStore [ "sandbox.db" ] . savecount ) . toEqual ( 3 ) ;
123
130
expect ( mem . hashStore [ "sandbox.db.0.0" ] . savecount ) . toEqual ( 2 ) ;
124
- expect ( mem . hashStore [ "sandbox.db.0.0" ] . savecount ) . toEqual ( 2 ) ;
131
+ expect ( mem . hashStore [ "sandbox.db.0.1" ] . savecount ) . toEqual ( 2 ) ;
132
+ expect ( mem . hashStore [ "sandbox.db.0.2" ] . savecount ) . toEqual ( 2 ) ;
133
+ expect ( mem . hashStore [ "sandbox.db.0.3" ] . savecount ) . toEqual ( 2 ) ;
125
134
expect ( mem . hashStore [ "sandbox.db.1.0" ] . savecount ) . toEqual ( 2 ) ;
126
135
127
136
// ok now lets load from it
@@ -141,7 +150,9 @@ describe("partitioning adapter", () => {
141
150
} ) . then ( ( ) => {
142
151
expect ( mem . hashStore [ "sandbox.db" ] . savecount ) . toEqual ( 4 ) ;
143
152
expect ( mem . hashStore [ "sandbox.db.0.0" ] . savecount ) . toEqual ( 2 ) ;
144
- expect ( mem . hashStore [ "sandbox.db.0.0" ] . savecount ) . toEqual ( 2 ) ;
153
+ expect ( mem . hashStore [ "sandbox.db.0.1" ] . savecount ) . toEqual ( 2 ) ;
154
+ expect ( mem . hashStore [ "sandbox.db.0.2" ] . savecount ) . toEqual ( 2 ) ;
155
+ expect ( mem . hashStore [ "sandbox.db.0.3" ] . savecount ) . toEqual ( 2 ) ;
145
156
expect ( mem . hashStore [ "sandbox.db.1.0" ] . savecount ) . toEqual ( 2 ) ;
146
157
expect ( mem . hashStore [ "sandbox.db.2.0" ] . savecount ) . toEqual ( 1 ) ;
147
158
0 commit comments