Mercurial > demo / examples/db/xdb/tests.lisp
changeset 41: |
81b7333f27f8 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Sun, 16 Jun 2024 22:15:04 -0400 |
permissions: |
-rw-r--r-- |
description: |
more examples |
2 (:use :cl :rt :obj/db :obj/id :xdb :obj/meta/storable)) 4 (in-package :xdb/tests) 8 (defparameter *tree* nil) 10 (defclass test-doc-non-storable (id) 20 :initform (make-hash-table) 28 (defclass test-doc-storable () 38 :initform (make-hash-table) 45 (:metaclass storable-class)) 47 (defun make-doc-test (type key data) 48 (let ((doc-obj (make-instance 'test-doc-storable :key key :type type))) 50 (setf (gethash (first pair) (data doc-obj)) (second pair))) 53 (defun test-store-doc (collection times) 55 (xdb::store-doc collection 62 (list "aa" (format nil "~R" (random 51234))) 63 (list "bb" (format nil "~R" (random 1234))) 64 (list "cc" (format nil "~R" (random 1234))) 65 (list "dd" (format nil "~R" (random 1234))) 66 (list "ee" (format nil "~R" (random 1234))) 67 (list "ff" (format nil "~R" (random 1234))) 68 (list "gg" (format nil "~R" (random 1234))) 69 (list "hh" (format nil "~R" (random 1234)))))))) 72 (let* ((db (make-instance 'xdb :location "/tmp/db-test/")) 73 (col (add-collection db "test" :load-from-file-p nil))) 74 (time (test-store-doc col n)) 75 ;; (time (snapshot db)) 76 ;; (time (sum col "eid")) 77 ;; (time (find-doc col "eid" 50)) 78 ;; (time (sort-collection col)) 81 (defun test-store-docx (collection times) 84 (xdb::store-doc collection 92 (list "aa" (random 51234)) 93 (list "bb" (format nil "~R" (random 1234))) 94 (list "cc" (format nil "~R" (random 1234))) 95 (list "dd" (format nil "~R" (random 1234))) 96 (list "ee" (format nil "~R" (random 1234))) 97 (list "ff" (format nil "~R" (random 1234))) 98 (list "gg" (format nil "~R" (random 1234))) 99 (list "hh" (get-universal-time)))) 102 (if (equal (mod i 100000) 0) 103 (sb-ext:gc :full t)))) 105 (defun test-store-doc-storable-object (collection times) 107 (xdb::store-doc collection 108 (make-instance 'test-doc-storable :key i :type "Test Doc" 112 :bb (format nil "~R" (random 1234)) 113 :cc (format nil "~R" (random 1234)) 114 :dd (format nil "~R" (random 1234)) 115 :ee (format nil "~R" (random 1234)) 116 :ff (format nil "~R" (random 1234)) 117 :hh (get-universal-time)) 121 (if (equal (mod i 100000) 0) 122 (sb-ext:gc :full t)))) 124 (defun test-store-doc-non-storable-object (collection times) 126 (xdb::store-doc collection 127 (make-instance 'test-doc-non-storable :key i :type "Test Doc" 131 :bb (format nil "~R" (random 1234)) 132 :cc (format nil "~R" (random 1234)) 133 :dd (format nil "~R" (random 1234)) 134 :ee (format nil "~R" (random 1234)) 135 :ff (format nil "~R" (random 1234)) 136 :hh (get-universal-time)) 140 (if (equal (mod i 100000) 0) 141 (sb-ext:gc :full t)))) 143 (defun test-store-doc-hash (collection times) 145 (let ((hash (make-hash-table :test 'equal))) 146 (setf (gethash 'key hash) i) 147 (setf (gethash "id" hash) i) 148 (setf (gethash "eid" hash) i) 149 (setf (gethash "bb" hash) (format nil "~R" (random 1234))) 150 (setf (gethash "cc" hash) (format nil "~R" (random 1234))) 151 (setf (gethash "dd" hash) (format nil "~R" (random 1234))) 152 (setf (gethash "ee" hash) (format nil "~R" (random 1234))) 153 (setf (gethash "ff" hash) (format nil "~R" (random 1234))) 154 (setf (gethash "stamp" hash) (get-universal-time)) 155 (xdb::store-doc collection hash)) 157 (if (equal (mod i 100000) 0) 158 (sb-ext:gc :full t)))) 161 (defun test-store-doc-list (collection times) 163 (xdb::store-doc collection (list 167 (list "aa" (random 51234)) 168 (list "bb" (format nil "~R" (random 1234))) 169 (list "cc" (format nil "~R" (random 1234))) 170 (list "dd" (format nil "~R" (random 1234))) 171 (list "ee" (format nil "~R" (random 1234))) 172 (list "ff" (format nil "~R" (random 1234))) 173 (list "gg" (format nil "~R" (random 1234))) 174 (list "stamp" (get-universal-time)))) 176 (if (equal (mod i 100000) 0) 177 (sb-ext:gc :full t)))) 179 (defparameter db (make-instance 'xdb :location "/tmp/db-test/")) 181 (defparameter col-hash (add-collection db "test-hash" :load-from-file-p nil)) 183 (defparameter col-list (add-collection db "test-list" :load-from-file-p nil)) 184 (defparameter col-object (add-collection db "test-object" :load-from-file-p nil)) 185 (defparameter col-object-storable (add-collection db "test-object-storable" :load-from-file-p nil)) 189 "Test database protocol." 190 (format t "Hash Test~%") 192 (time (test-store-doc-hash col-hash 10000)) 194 (time (xdb::sum col-hash :element "id")) 196 (time (xdb::find-doc col-hash :test (lambda (doc) (equal (get-val doc "id") 500)))) 198 (time (xdb::sort-collection col-hash)) 199 (format t "List Test~%") 201 (time (test-store-doc-list col-list 10000)) 203 (time (xdb::sum col-list :element "id")) 205 (time (xdb::find-doc col-list :test (lambda (doc) (equal (get-val doc "id") 500)))) 207 (time (xdb::sort-collection col-list)) 210 (format t "Object non storable Test~%") 212 (time (test-store-doc-non-storable-object col-object 10000)) 214 (time (xdb::sum col-object :element 'id)) 216 (time (xdb::find-doc col-object :test (lambda (doc) (equal (get-val doc 'id) 500)))) 218 (time (xdb::sort-collection col-object)) 221 (setf xdb::*fsync-data* nil) 222 (format t "Object storable Test~%") 224 (time (test-store-doc-storable-object col-object-storable 10000)) 226 (time (xdb::sum col-object-storable :element 'id)) 228 (time (xdb::find-doc col-object-storable :test (lambda (doc) (equal (get-val doc 'id) 500)))) 230 (time (xdb::sort-collection col-object-storable)))