fileAttrs = { "CacheEnabled" : "true", "ContentType" : "text/plain", "ReplicationParameters" : replicationParams } celestefs.create(path, attrs=fileAttrs) # # Repeatedly ingest and fill the file, read it back to compare it with the # original, and truncate it. (If profiling is enabled, each repetition # will append information to timingsFile.) # remainingRepetitions = repetitions while repetitions <= 0 or remainingRepetitions > 0: pCat = Popen(["/bin/cat", localFile], stdout=PIPE) pWrite = celestefs.pwrite(path, 0, stdin=pCat.stdout) pWrite.communicate() pRead = celestefs.pread(path, 0, -1, stdout=PIPE) pCmp = Popen(["/usr/bin/cmp", localFile, "-"], stdin=pRead.stdout, stdout=PIPE) pCmp.communicate()[0] if pCmp.returncode != 0: print "%s does not compare identical to %s; exiting" % \ (path, localFile) celestefs.setLength(path, 0) remainingRepetitions = remainingRepetitions - 1
# pRead = celestefs.pread(celesteFilePath2, 0, -1, stdout=PIPE) pCmp = Popen(["/usr/bin/cmp", inFileName, "-"], stdin=pRead.stdout, stdout=PIPE) print pCmp.communicate()[0] # # Write the file's contents if necessary. # statOutput = celestefs.stat(celesteFilePath, options=["-s"]) fileSize = int(statOutput.split()[1]) print >> stderr, "file size: %d" % fileSize if fileSize == 0: pCat = Popen(["/bin/cat", inFileName], stdout=PIPE) pWrite = celestefs.pwrite(celesteFilePath, 0, stdin=pCat.stdout, bufferSize=134217728) pWrite.communicate() statOutput = celestefs.stat(celesteFilePath, options=["-s"]) fileSize = int(statOutput.split()[1]) print >> stderr, "file size now: %d" % fileSize # # Read the file and compare it to the local file we used to initialize # it. # pRead = celestefs.pread(celesteFilePath, 0, -1, stdout=PIPE) pCmp = Popen(["/usr/bin/cmp", inFileName, "-"], stdin=pRead.stdout, stdout=PIPE) print pCmp.communicate()[0]
# Create or truncate the test file, as approriate. # if not c.fileExists(filename): createAttrs = { # "BlockSize" : "3" # "BlockSize" : "16" } c.create(filename, contentType="text/plain", attrs=createAttrs) else: c.setLength(filename, 0) # # Write a sequence of characters that give clues to their offsets in the # file. # p = c.pwrite(filename) p.stdin.write("0123456789012345678901234567890123456789") p.communicate() # # See what we have so far. # p = c.pread(filename) output = p.communicate()[0] print '%s\'s contents: "%s"' % (filename, output) # # Now for the test proper. Overwrite some of the data in the middle with # something else. # p = c.pwrite(filename, offset=5)