summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-06 18:03:49 +0200
committerLars Wirzenius <liw@liw.fi>2021-02-06 18:16:45 +0200
commit61aca01941d3bdf324a207f2b53dbf7128169142 (patch)
tree861aa3b61e16e2a486c61eabf1bf2e27a223679e
parentad98db921aa3d710ad7c448c6a1b818f4359d73a (diff)
downloadobnam2-61aca01941d3bdf324a207f2b53dbf7128169142.tar.gz
test: add scenario for checking chunk-size
-rw-r--r--obnam.md27
-rw-r--r--subplot/data.py15
-rw-r--r--subplot/data.yaml4
-rw-r--r--subplot/server.py21
-rw-r--r--subplot/server.yaml3
5 files changed, 53 insertions, 17 deletions
diff --git a/obnam.md b/obnam.md
index b41a118..34535a5 100644
--- a/obnam.md
+++ b/obnam.md
@@ -771,6 +771,10 @@ The server has the following API for managing chunks:
* `GET /chunks?sha256=xyzzy` &ndash; find chunks on the server whose
metadata indicates their contents has a given SHA256 checksum
* `GET /chunks?generation=true` &ndash; find generation chunks
+* `GET /chunks?data=True` &ndash; find chunks with file data
+ - this is meant for testing only
+ - it excludes generation chunks, and chunks used to store the
+ generation's SQLite file
HTTP status codes are used to indicate if a request succeeded or not,
using the customary meanings.
@@ -858,6 +862,7 @@ when I POST data.dat to /chunks, with chunk-meta: {"sha256":"abc"}
then HTTP status code is 201
and content-type is application/json
and the JSON body has a field chunk_id, henceforth ID
+and server has 1 file chunks
~~~
We must be able to retrieve it.
@@ -1145,6 +1150,28 @@ given a manifest of the directory live restored in rest in rest.yaml
then files live.yaml and rest.yaml match
~~~
+## Set chunk size
+
+This scenario verifies that the user can set the chunk size in the
+configuration file. The chunk size only affects the chunks of live
+data.
+
+~~~scenario
+given an installed obnam
+given a running chunk server
+given a client config based on tiny-chunk-size.yaml
+given a file live/data.dat containing "abc"
+when I run obnam --config tiny-chunk-size.yaml backup
+then server has 3 file chunks
+~~~
+
+~~~{#tiny-chunk-size.yaml .file .yaml .numberLines}
+verify_tls_cert: false
+root: live
+chunk_size: 1
+~~~
+
+
## Backup or not for the right reason
The decision of whether to back up a file or keep the version in the
diff --git a/subplot/data.py b/subplot/data.py
index 2a54037..f3faf2b 100644
--- a/subplot/data.py
+++ b/subplot/data.py
@@ -5,14 +5,17 @@ import random
import yaml
-def create_file_with_random_data(ctx, filename=None):
- N = 128
- data = "".join(chr(random.randint(0, 255)) for i in range(N)).encode("UTF-8")
+def create_file_with_given_data(ctx, filename=None, data=None):
+ logging.debug(f"creating file {filename} with {data!r}")
dirname = os.path.dirname(filename) or "."
- logging.debug(f"create_file_with_random_data: dirname={dirname}")
os.makedirs(dirname, exist_ok=True)
- with open(filename, "wb") as f:
- f.write(data)
+ open(filename, "wb").write(data.encode("UTF-8"))
+
+
+def create_file_with_random_data(ctx, filename=None):
+ N = 128
+ data = "".join(chr(random.randint(0, 255)) for i in range(N))
+ create_file_with_given_data(ctx, filename=filename, data=data)
def create_nonutf8_filename(ctx, dirname=None):
diff --git a/subplot/data.yaml b/subplot/data.yaml
index 6d384b8..9538daa 100644
--- a/subplot/data.yaml
+++ b/subplot/data.yaml
@@ -1,6 +1,4 @@
-- given: >
- a file (?P<filename>\\S+) containing "(?P<data>.*)"
- regex: true
+- given: a file {filename} containing "{data:text}"
function: create_file_with_given_data
- given: "a file {filename} containing some random data"
diff --git a/subplot/server.py b/subplot/server.py
index 289e181..df594f7 100644
--- a/subplot/server.py
+++ b/subplot/server.py
@@ -5,8 +5,6 @@ import random
import re
import requests
import shutil
-import socket
-import time
import urllib3
import yaml
@@ -35,7 +33,9 @@ def start_chunk_server(ctx):
"address": f"localhost:{port}",
}
- server_binary = os.path.abspath(os.path.join(srcdir, "target", "debug", "obnam-server"))
+ server_binary = os.path.abspath(
+ os.path.join(srcdir, "target", "debug", "obnam-server")
+ )
filename = "config.yaml"
yaml.safe_dump(config, stream=open(filename, "w"))
@@ -44,11 +44,7 @@ def start_chunk_server(ctx):
ctx["server_url"] = f"https://{config['address']}"
daemon_start_on_port(
- ctx,
- name="obnam-server",
- path=server_binary,
- args=filename,
- port=port,
+ ctx, name="obnam-server", path=server_binary, args=filename, port=port
)
@@ -138,6 +134,15 @@ def json_body_matches(ctx, wanted=None):
assert_eq(body.get(key, "not.there"), wanted[key])
+def server_has_n_file_chunks(ctx, n=None):
+ assert_eq = globals()["assert_eq"]
+ n = int(n)
+ url = f"{ctx['server_url']}/chunks?data=true"
+ _request(ctx, requests.get, url)
+ num_chunks = len(ctx["http.json"])
+ assert_eq(n, num_chunks)
+
+
# Make an HTTP request.
def _request(ctx, method, url, headers=None, data=None):
r = method(url, headers=headers, data=data, verify=False)
diff --git a/subplot/server.yaml b/subplot/server.yaml
index 68f8f0c..60f8a44 100644
--- a/subplot/server.yaml
+++ b/subplot/server.yaml
@@ -43,3 +43,6 @@
- then: "the body matches file {filename}"
function: body_matches_file
+
+- then: "server has {n:int} file chunks"
+ function: server_has_n_file_chunks