Ejemplo n.º 1
0
class ParseGCLogTest(unittest.TestCase):
    """Test cases for writing parsed GC data to CSV files"""
    
    path = os.path.dirname(os.path.abspath(__file__)) + "/"
    result_file = path + "results.csv"
    sample_file = path + "gc-sample.log"

    def setUp(self):
        self.parser = ParseGCLog()
        self.csv_writer = FileResultWriter()
        
    def tearDown(self):
        if os.path.isfile(self.result_file):
            os.remove(self.result_file)

    def test_parse_file(self):
        result = self.parser.parse_file(self.path + "gc-sample.log")
        self.assertEqual(len(result), 7)

    def test_generate_memory_csv(self):
        expected_file = self.path + "expected_mem.csv"
        result = self.parser.parse_file(self.sample_file)
        graph.generate_graph(None, 
            graph.YG_GC_MEMORY, 
            result, 
            self.csv_writer, 
            False, 
            self.result_file)
        self.assertTrue(filecmp.cmp(self.result_file, expected_file))

    def test_generate_gc_reclaimed_csv(self):
        expected_file = self.path + "expected_reclaimed.csv"
        result = self.parser.parse_file(self.sample_file)
        graph.generate_graph(None, 
            graph.MEMORY_RECLAIMED, 
            result, 
            self.csv_writer, 
            False, 
            self.result_file)
        self.assertTrue(filecmp.cmp(self.result_file, expected_file))
        
    def test_generate_gc_duration_csv(self):
        expected_file = self.path + "expected_duration.csv"
        result = self.parser.parse_file(self.sample_file)
        graph.generate_graph(None, 
            graph.GC_DURATION, 
            result, 
            self.csv_writer, 
            False, 
            self.result_file)
        self.assertTrue(filecmp.cmp(self.result_file, expected_file))
Ejemplo n.º 2
0
class ParseGCLogTest(unittest.TestCase):
    """Test cases for writing parsed GC data to CSV files"""

    path = os.path.dirname(os.path.abspath(__file__)) + "/"
    result_file = path + "results.csv"
    sample_file = path + "gc-sample.log"

    def setUp(self):
        self.parser = ParseGCLog()
        self.csv_writer = FileResultWriter()

    def tearDown(self):
        if os.path.isfile(self.result_file):
            os.remove(self.result_file)

    def test_parse_file(self):
        result = self.parser.parse_file(self.path + "gc-sample.log")
        self.assertEqual(len(result), 7)

    def test_generate_memory_csv(self):
        expected_file = self.path + "expected_mem.csv"
        result = self.parser.parse_file(self.sample_file)
        graph.generate_graph(None, graph.YG_GC_MEMORY, result, self.csv_writer,
                             False, self.result_file)
        self.assertTrue(filecmp.cmp(self.result_file, expected_file))

    def test_generate_gc_reclaimed_csv(self):
        expected_file = self.path + "expected_reclaimed.csv"
        result = self.parser.parse_file(self.sample_file)
        graph.generate_graph(None, graph.MEMORY_RECLAIMED, result,
                             self.csv_writer, False, self.result_file)
        self.assertTrue(filecmp.cmp(self.result_file, expected_file))

    def test_generate_gc_duration_csv(self):
        expected_file = self.path + "expected_duration.csv"
        result = self.parser.parse_file(self.sample_file)
        graph.generate_graph(None, graph.GC_DURATION, result, self.csv_writer,
                             False, self.result_file)
        self.assertTrue(filecmp.cmp(self.result_file, expected_file))
class ParseGCBlobTest(unittest.TestCase):

    path = os.path.dirname(os.path.abspath(__file__)) + "/"
    blobstore_dir = path + "testbed.blobstore"
    sample_file = path + "gc-sample.log"

    def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = TestbedWithFiles()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_blobstore_stub(self.blobstore_dir)

        self.parser = ParseGCLog()
        self.csv_writer = BlobResultWriter()

    def tearDown(self):
        self.testbed.deactivate()
        if os.path.isdir(self.blobstore_dir):
            shutil.rmtree(self.blobstore_dir)

    def _load_file_data(self, filename):
        file = open(filename, 'r')
        data = file.read()
        file.close()
        return data

    def _load_blob_data(self, blob_key):
        blob_info = blobstore.BlobInfo.get(blob_key)
        blob_reader = blob_info.open()
        data = blob_reader.read()
        blob_reader.close()
        return data

    def test_generate_memory_csv(self):
        expected_data = self._load_file_data(self.path + "expected_mem.csv")
        gc_data = self.parser.parse_file(self.sample_file)
        log_key = LogData(
            filename="memory.tmp",
            notes="notes").put()
        blob_key = graph.generate_cached_graph(log_key, 
            graph.YG_GC_MEMORY, 
            gc_data, 
            self.csv_writer)
        result_data = self._load_blob_data(blob_key)
        self.assertEqual(result_data, expected_data)

    def test_generate_gc_reclaimed_csv(self):
        expected_data = self._load_file_data(self.path + "expected_reclaimed.csv")
        gc_data = self.parser.parse_file(self.sample_file)
        log_key = LogData(
            filename="reclaimed.tmp",
            notes="notes").put()
        blob_key = graph.generate_cached_graph(log_key, 
            graph.MEMORY_RECLAIMED, 
            gc_data, 
            self.csv_writer)
        result_data = self._load_blob_data(blob_key)
        self.assertEqual(result_data, expected_data)

    def test_generate_gc_duration_csv(self):
        expected_data = self._load_file_data(self.path + "expected_duration.csv")
        gc_data = self.parser.parse_file(self.sample_file)
        log_key = LogData(
            filename="duration.tmp",
            notes="notes").put()
        blob_key = graph.generate_cached_graph(log_key, 
            graph.GC_DURATION, 
            gc_data, 
            self.csv_writer)
        result_data = self._load_blob_data(blob_key)
        self.assertEqual(result_data, expected_data)

    def test_gc_datastore(self):
        """Test storage & retrival of GC entries in datastore"""
        yg_gc = parsegc.generate_yg_gc_entry(
            "100.25",
            "100.25",
            "ParNew",
            "3",
            "2",
            "8",
            "0.12345",
            "8192",
            "5120",
            "16384",
            "3.12345",
            "1.5",
            "2.0",
            "3.1")

        full_gc = parsegc.generate_full_gc_entry(
            "200.5",
            "200.5",
            "Tenured",
            "20",
            "10",
            "40",
            "0.23456",
            "8192",
            "5120",
            "16384",
            "200",
            "100",
            "400",
            "3.1234",
            "1.9",
            "0.05",
            "3.11")

        # Items should be written to & returned from the store
        # ordered by timestamp
        gc_data = [yg_gc, full_gc]

        log_key = LogData(
            filename="test_gc_datastore.tmp",
            notes="notes").put()

        gc_datastore.store_data(log_key, gc_data)

        results = gc_datastore.get_data(log_key)

        self.assertEqual(results, gc_data)
        
        # Uncomment below to help debug failures
        """
Ejemplo n.º 4
0
class ParseGCBlobTest(unittest.TestCase):

    path = os.path.dirname(os.path.abspath(__file__)) + "/"
    blobstore_dir = path + "testbed.blobstore"
    sample_file = path + "gc-sample.log"

    def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = TestbedWithFiles()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_blobstore_stub(self.blobstore_dir)

        self.parser = ParseGCLog()
        self.csv_writer = BlobResultWriter()

    def tearDown(self):
        self.testbed.deactivate()
        if os.path.isdir(self.blobstore_dir):
            shutil.rmtree(self.blobstore_dir)

    def _load_file_data(self, filename):
        file = open(filename, 'r')
        data = file.read()
        file.close()
        return data

    def _load_blob_data(self, blob_key):
        blob_info = blobstore.BlobInfo.get(blob_key)
        blob_reader = blob_info.open()
        data = blob_reader.read()
        blob_reader.close()
        return data

    def test_generate_memory_csv(self):
        expected_data = self._load_file_data(self.path + "expected_mem.csv")
        gc_data = self.parser.parse_file(self.sample_file)
        log_key = LogData(filename="memory.tmp", notes="notes").put()
        blob_key = graph.generate_cached_graph(log_key, graph.YG_GC_MEMORY,
                                               gc_data, self.csv_writer)
        result_data = self._load_blob_data(blob_key)
        self.assertEqual(result_data, expected_data)

    def test_generate_gc_reclaimed_csv(self):
        expected_data = self._load_file_data(self.path +
                                             "expected_reclaimed.csv")
        gc_data = self.parser.parse_file(self.sample_file)
        log_key = LogData(filename="reclaimed.tmp", notes="notes").put()
        blob_key = graph.generate_cached_graph(log_key, graph.MEMORY_RECLAIMED,
                                               gc_data, self.csv_writer)
        result_data = self._load_blob_data(blob_key)
        self.assertEqual(result_data, expected_data)

    def test_generate_gc_duration_csv(self):
        expected_data = self._load_file_data(self.path +
                                             "expected_duration.csv")
        gc_data = self.parser.parse_file(self.sample_file)
        log_key = LogData(filename="duration.tmp", notes="notes").put()
        blob_key = graph.generate_cached_graph(log_key, graph.GC_DURATION,
                                               gc_data, self.csv_writer)
        result_data = self._load_blob_data(blob_key)
        self.assertEqual(result_data, expected_data)

    def test_gc_datastore(self):
        """Test storage & retrival of GC entries in datastore"""
        yg_gc = parsegc.generate_yg_gc_entry("100.25", "100.25", "ParNew", "3",
                                             "2", "8", "0.12345", "8192",
                                             "5120", "16384", "3.12345", "1.5",
                                             "2.0", "3.1")

        full_gc = parsegc.generate_full_gc_entry("200.5", "200.5", "Tenured",
                                                 "20", "10", "40", "0.23456",
                                                 "8192", "5120", "16384",
                                                 "200", "100", "400", "3.1234",
                                                 "1.9", "0.05", "3.11")

        # Items should be written to & returned from the store
        # ordered by timestamp
        gc_data = [yg_gc, full_gc]

        log_key = LogData(filename="test_gc_datastore.tmp",
                          notes="notes").put()

        gc_datastore.store_data(log_key, gc_data)

        results = gc_datastore.get_data(log_key)

        self.assertEqual(results, gc_data)

        # Uncomment below to help debug failures
        """