#!/bin/sh
# Write a map with the installed MVStore, close it, open the file again and
# read it back; check the file's format header is the 1.4 one (format 1).
set -eu
cd "$AUTOPKGTEST_TMP"

cat > Store.java <<'EOF'
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;

public class Store {
    public static void main(String[] args) {
        try (MVStore s = MVStore.open(args[0])) {
            MVMap<Integer, String> m = s.openMap("data");
            for (int i = 0; i < 1000; i++) m.put(i, "v" + i);
            s.commit();
        }
        try (MVStore s = MVStore.open(args[0])) {
            MVMap<Integer, String> m = s.openMap("data");
            System.out.println(m.size() + " " + m.get(999));
        }
    }
}
EOF

out=$(java -cp /usr/share/java/h2-mvstore-1.4.jar Store.java test.mv.db)
[ "$out" = "1000 v999" ] || { echo "FAIL: got '$out'"; exit 1; }
head -c 200 test.mv.db | grep -q "format:1"
echo "ok: stored, read back, format 1"
