File: retry.lisp

package info (click to toggle)
pgloader 3.6.10-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,060 kB
  • sloc: sql: 32,321; lisp: 14,793; makefile: 435; sh: 85; python: 26
file content (50 lines) | stat: -rw-r--r-- 1,762 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
;;; Test cases for issue https://github.com/dimitri/pgloader/issues/22
;;;
;;;

#|
CREATE TABLE `retry` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `content` text,
  PRIMARY KEY (`id`)
);
|#

(defpackage #:pgloader.test.retry
  (:use #:cl #:pgloader.params #:pgloader.mysql)
  (:export #:produce-data))

(in-package #:pgloader.test.retry)

(defvar *inject-null-bytes*
  (coerce (loop for previous = 0 then (+ previous offset)
             for offset in '(15769 54 7 270 8752)
             collect (+ previous offset)) 'vector)
  "Line numbers in the batch where to inject erroneous data.")

(defvar *string-with-null-byte* (concatenate 'string "Hello" (list #\Nul) "World!"))

(defvar *random-string* (make-string (random 42) :initial-element #\a)
  "A random string.")

(defvar *query* "INSERT INTO `~a`(`content`) VALUES ('~a')")

(defun produce-data (&key
                       (*myconn-host* *myconn-host*)
                       (*myconn-port* *myconn-port*)
                       (*myconn-user* *myconn-user*)
                       (*myconn-pass* *myconn-pass*)
                       (dbname "retry")
                       (table-name "retry")
                       (rows 150000))
  "Produce a data set that looks like the one in issue #22."
  (with-mysql-connection (dbname)
    (let ((next-error-pos 0))
      (loop for n from 1 to rows
         for str = (if (and (< next-error-pos (length *inject-null-bytes*))
                            (= n (aref *inject-null-bytes* next-error-pos)))
                       (progn
                         (incf next-error-pos)
                         *string-with-null-byte*)
                       *random-string*)
         do (pgloader.mysql::mysql-query (format nil *query* table-name str))))))