def test_wal_header_pg92(): header = b'q\xd0\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xef\xfc\rW' walheader = wal.read_header(header) assert walheader.lsn == "0/1000000" assert walheader.filename == "000000010000000000000001" constructed_header = wal_header_for_file("000000010000000000000001", version=90200) # Ignore the useless rem_len field assert constructed_header[:-4] == header[:-4]
def _verify_wal(self, filetype, filename, path): if filetype != "xlog": return try: with open(path, "rb") as fp: hdr = wal.read_header(fp.read(wal.WAL_HEADER_LEN)) except (KeyError, OSError, ValueError) as ex: fmt = "WAL file {path!r} verification failed: {ex.__class__.__name__}: {ex}" raise HttpResponse(fmt.format(path=path, ex=ex), status=412) expected_lsn = wal.lsn_from_name(filename) if hdr.lsn != expected_lsn: fmt = "Expected LSN {lsn!r} in restored WAL file {path!r}; found {found!r}" raise HttpResponse(fmt.format(lsn=expected_lsn, path=path, found=hdr.lsn), status=412)
def test_wal_header(): blob95 = WAL_HEADER_95 hdr95 = wal.WalHeader(version=90500, timeline=47, lsn='11/9C000000', filename='0000002F000000110000009C') assert wal.read_header(blob95) == hdr95 # only first 20 bytes are used assert wal.read_header(blob95 + b"XXX") == hdr95 with pytest.raises(ValueError): wal.read_header(blob95[:18]) blob94 = b"\x7e\xd0" + blob95[2:] hdr94 = hdr95._replace(version=90400) assert wal.read_header(blob94) == hdr94 blob9X = b"\x7F\xd0" + blob95[2:] with pytest.raises(KeyError): wal.read_header(blob9X)
def test_wal_header_pg95(): header = b'\x87\xd0\x02\x00\x01\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x00' walheader = wal.read_header(header) assert walheader.lsn == "0/B000000" assert walheader.filename == "00000001000000000000000B"