Search in sources :

Example 1 with CacheAnalysis

use of com.att.aro.core.packetanalysis.pojo.CacheAnalysis in project VideoOptimzer by attdevsupport.

the class DuplicateContentImpl method runTest.

@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
    DuplicateContentResult result = new DuplicateContentResult();
    CacheAnalysis cacheAnalysis = tracedata.getCacheAnalysis();
    result.setDuplicateContentBytes(cacheAnalysis.getDuplicateContentBytes());
    result.setDuplicateContentBytesRatio(cacheAnalysis.getDuplicateContentBytesRatio());
    int duplicateContentsize = cacheAnalysis.getDuplicateContent().size();
    result.setDuplicateContentsize(duplicateContentsize);
    long totalTCPBytes = 0;
    if (tracedata.getStatistic() != null) {
        totalTCPBytes = tracedata.getStatistic().getTotalTCPPayloadBytes();
    }
    result.setTotalContentBytes(totalTCPBytes);
    List<CacheEntry> caUResult = cacheAnalysis.getDuplicateContent();
    result.setDuplicateContentList(caUResult);
    int duplicateContentSizeOfUniqueItems = caUResult.size();
    result.setDuplicateContentSizeOfUniqueItems(duplicateContentSizeOfUniqueItems);
    if (duplicateContentsize <= 3) {
        result.setResultType(BPResultType.PASS);
        result.setResultText(textResultPass);
        result.setResultExcelText(BPResultType.PASS.getDescription());
    } else {
        result.setResultType(BPResultType.FAIL);
        DecimalFormat numf = new DecimalFormat("#.##");
        NumberFormat numf2 = NumberFormat.getInstance();
        numf2.setMaximumFractionDigits(3);
        String text = MessageFormat.format(textResults, numf.format(result.getDuplicateContentBytes() * 100.0 / result.getTotalContentBytes()), result.getDuplicateContentSizeOfUniqueItems(), numf2.format(((double) result.getDuplicateContentBytes()) / DUPLICATE_CONTENT_DENOMINATOR), numf2.format(((double) result.getTotalContentBytes()) / DUPLICATE_CONTENT_DENOMINATOR));
        result.setResultText(text);
        result.setResultExcelText(MessageFormat.format(textExcelResults, BPResultType.FAIL.getDescription(), result.getDuplicateContentSizeOfUniqueItems(), numf2.format(((double) result.getDuplicateContentBytes()) / DUPLICATE_CONTENT_DENOMINATOR), numf2.format(((double) result.getTotalContentBytes()) / DUPLICATE_CONTENT_DENOMINATOR), numf.format(result.getDuplicateContentBytes() * 100.0 / result.getTotalContentBytes())));
    }
    result.setAboutText(aboutText);
    result.setDetailTitle(detailTitle);
    result.setLearnMoreUrl(learnMoreUrl);
    result.setOverviewTitle(overviewTitle);
    result.setExportAllFiles(exportAllFiles);
    result.setExportAllPct(exportAllPct);
    result.setStaticsUnitsMbytes(staticsUnitsMbytes);
    return result;
}
Also used : DuplicateContentResult(com.att.aro.core.bestpractice.pojo.DuplicateContentResult) CacheAnalysis(com.att.aro.core.packetanalysis.pojo.CacheAnalysis) DecimalFormat(java.text.DecimalFormat) CacheEntry(com.att.aro.core.packetanalysis.pojo.CacheEntry) NumberFormat(java.text.NumberFormat)

Example 2 with CacheAnalysis

use of com.att.aro.core.packetanalysis.pojo.CacheAnalysis in project VideoOptimzer by attdevsupport.

the class CacheAnalysisImpl method analyze.

@Override
public CacheAnalysis analyze(List<Session> sessionlist) {
    long analysisStartTime = System.currentTimeMillis();
    CacheAnalysis result = new CacheAnalysis();
    long totalRequestResponseBytes = 0;
    long totalRequestResponseDupBytes = 0;
    double duplicateContentBytesRatio = 0.0;
    Map<String, CacheEntry> cacheEntries = new HashMap<String, CacheEntry>();
    Map<String, CacheEntry> dupEntries = new HashMap<String, CacheEntry>();
    Map<String, SortedSet<Range>> rangeEntries = new HashMap<String, SortedSet<Range>>();
    List<CacheEntry> diagnosisResults = new ArrayList<CacheEntry>();
    List<CacheEntry> duplicateContent = new ArrayList<CacheEntry>();
    List<CacheEntry> duplicateContentWithOriginals = new ArrayList<CacheEntry>();
    Map<CacheExpiration, List<CacheEntry>> cacheExpirationResponses = result.getCacheExpirationResponses();
    duplicateEntries = new ArrayList<DuplicateEntry>();
    // Initialize cache expiration lists
    for (CacheExpiration expiration : CacheExpiration.values()) {
        cacheExpirationResponses.put(expiration, new ArrayList<CacheEntry>());
    }
    // Build a sorted list of all of the HTTP request/response in the trace
    List<HttpRequestResponseInfoWithSession> rrInfo = new ArrayList<HttpRequestResponseInfoWithSession>();
    for (Session session : sessionlist) {
        if (!session.isUdpOnly()) {
            // rrInfo.addAll(session.getRequestResponseInfo());
            for (HttpRequestResponseInfo item : session.getRequestResponseInfo()) {
                HttpRequestResponseInfoWithSession itemsession = new HttpRequestResponseInfoWithSession();
                itemsession.setInfo(item);
                itemsession.setSession(session);
                rrInfo.add(itemsession);
            }
        }
    }
    Collections.sort(rrInfo);
    // Iterate through responses looking for duplicates
    for (HttpRequestResponseInfoWithSession httpreqres : rrInfo) {
        HttpRequestResponseInfo response = httpreqres.getInfo();
        Session session = httpreqres.getSession();
        PacketInfo firstPacket = session.getTcpPackets().get(0);
        if (response.getDirection() == HttpDirection.REQUEST) {
            // We only want to process responses
            continue;
        }
        // Check whether response is valid
        int statusCode = response.getStatusCode();
        if (statusCode == 0) {
            diagnosisResults.add(new CacheEntry(null, response, Diagnosis.CACHING_DIAG_INVALID_RESPONSE, 0, firstPacket));
            continue;
        }
        if (statusCode != 200 && statusCode != 206) {
            diagnosisResults.add(new CacheEntry(null, response, Diagnosis.CACHING_DIAG_INVALID_REQUEST, 0, firstPacket));
            continue;
        }
        // [A] Find corresponding request
        HttpRequestResponseInfo request = response.getAssocReqResp();
        if (request == null) {
            diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_REQUEST_NOT_FOUND, 0, firstPacket));
            continue;
        }
        totalRequestResponseBytes += response.getContentLength();
        // Request must by GET, POST, or PUT
        String requestType = request.getRequestType();
        if (!HttpRequestResponseInfo.HTTP_GET.equals(requestType) && !HttpRequestResponseInfo.HTTP_PUT.equals(requestType) && !HttpRequestResponseInfo.HTTP_POST.equals(requestType)) {
            diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_INVALID_REQUEST, 0, firstPacket));
            continue;
        }
        // Check for valid object name and host name
        if (request.getHostName() == null || request.getObjName() == null) {
            diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_INVALID_OBJ_NAME, 0, firstPacket));
            continue;
        }
        // [B] Object cacheable?
        if (response.isNoStore() || request.isNoStore() || HttpRequestResponseInfo.HTTP_POST.equals(requestType) || HttpRequestResponseInfo.HTTP_PUT.equals(requestType)) {
            cacheEntries.remove(getObjFullName(request, response));
            dupEntries.remove(getObjDuplicateName(request, response));
            diagnosisResults.add(new CacheEntry(request, response, Diagnosis.CACHING_DIAG_NOT_CACHABLE, 0, firstPacket));
            continue;
        }
        // [C] Does it hit the cache?
        CacheEntry cacheEntry = cacheEntries.get(getObjFullName(request, response));
        CacheEntry cacheDuplicateEntry = dupEntries.get(getObjDuplicateName(request, response));
        CacheEntry newCacheEntry;
        if (cacheEntry == null) {
            Diagnosis diagnosis = Diagnosis.CACHING_DIAG_CACHE_MISSED;
            newCacheEntry = new CacheEntry(request, response, diagnosis, firstPacket);
            newCacheEntry.setSession(session);
            addToCache(newCacheEntry, rangeEntries, cacheEntries, dupEntries, session);
            newCacheEntry.setCacheCount(1);
            diagnosisResults.add(newCacheEntry);
            if (cacheDuplicateEntry != null) {
                diagnosis = Diagnosis.CACHING_DIAG_ETAG_DUPLICATE;
            }
            duplicateEntries.add(new DuplicateEntry(request, response, diagnosis, firstPacket, session, getContent(response, session)));
            continue;
        } else {
            int oldCount = cacheEntry.getCacheCount();
            cacheEntry.setCacheCount(oldCount + 1);
        }
        CacheExpiration expStatus = cacheExpired(cacheEntry, request.getAbsTimeStamp());
        SortedSet<Range> ranges = rangeEntries.get(getObjFullName(cacheEntry.getRequest(), cacheEntry.getResponse()));
        boolean isfullcachehit = isFullCacheHit(response, ranges);
        if (isfullcachehit) {
            // [D] Is it expired?
            switch(expStatus) {
                case CACHE_EXPIRED:
                case CACHE_EXPIRED_HEURISTIC:
                    newCacheEntry = handleCacheExpired(session, response, request, firstPacket, cacheEntry);
                    diagnosisResults.add(newCacheEntry);
                    break;
                case CACHE_NOT_EXPIRED:
                case CACHE_NOT_EXPIRED_HEURISTIC:
                    newCacheEntry = new CacheEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP, firstPacket);
                    duplicateEntries.add(new DuplicateEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP, firstPacket, session, getContent(response, session)));
                    diagnosisResults.add(newCacheEntry);
                    break;
                default:
                    // Should not occur
                    newCacheEntry = null;
            }
        } else {
            long bytesInCache = getBytesInCache(response, ranges);
            // [D] Is it expired?
            switch(expStatus) {
                case CACHE_EXPIRED:
                case CACHE_EXPIRED_HEURISTIC:
                    newCacheEntry = handleCacheExpiredWithByteInCache(session, response, request, firstPacket, cacheEntry, bytesInCache);
                    diagnosisResults.add(newCacheEntry);
                    break;
                case CACHE_NOT_EXPIRED:
                case CACHE_NOT_EXPIRED_HEURISTIC:
                    newCacheEntry = new CacheEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT, bytesInCache, firstPacket);
                    duplicateEntries.add(new DuplicateEntry(request, response, Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP, firstPacket, session, getContent(response, session)));
                    diagnosisResults.add(newCacheEntry);
                    break;
                default:
                    // Should not occur
                    newCacheEntry = null;
            }
        }
        cacheExpirationResponses.get(expStatus).add(newCacheEntry);
        if (newCacheEntry != null) {
            newCacheEntry.setCacheHit(cacheEntry);
        }
    // addToCache(newCacheEntry);
    }
    // END: Iterate through responses looking for duplicates
    // Get cache problems
    Set<CacheEntry> dupsWithOrig = new HashSet<CacheEntry>();
    Map<String, DuplicateEntry> duplicateEntriesMap = new HashMap<String, DuplicateEntry>();
    CacheEntry cache;
    for (DuplicateEntry dupEntry : duplicateEntries) {
        if (dupEntry.getContentLength() > 0) {
            String key = dupEntry.getRequest().getHostName() + dupEntry.getHttpObjectName() + dupEntry.getContentLength();
            if (dupEntry.getHttpObjectName() != null) {
                if (!duplicateEntriesMap.containsKey(key)) {
                    dupEntry.setCount(1);
                    duplicateEntriesMap.put(key, dupEntry);
                } else {
                    if (Arrays.equals(duplicateEntriesMap.get(key).getContent(), dupEntry.getContent())) {
                        int count = duplicateEntriesMap.get(key).getCount();
                        if (count == 1) {
                            cache = new CacheEntry(duplicateEntriesMap.get(key).getRequest(), duplicateEntriesMap.get(key).getResponse(), duplicateEntriesMap.get(key).getDiagnosis(), duplicateEntriesMap.get(key).getSessionFirstPacket());
                            cache.setSession(dupEntry.getSession());
                            dupsWithOrig.add(cache);
                        }
                        cache = new CacheEntry(dupEntry.getRequest(), dupEntry.getResponse(), dupEntry.getDiagnosis(), dupEntry.getSessionFirstPacket());
                        dupsWithOrig.add(cache);
                        dupEntry = new DuplicateEntry(dupEntry.getRequest(), dupEntry.getResponse(), dupEntry.getDiagnosis(), dupEntry.getSessionFirstPacket(), dupEntry.getSession(), dupEntry.getContent());
                        dupEntry.setCount(count + 1);
                        duplicateEntriesMap.replace(key, dupEntry);
                    }
                }
            }
        }
    }
    for (Entry<String, DuplicateEntry> cacheEntry2 : duplicateEntriesMap.entrySet()) {
        if (cacheEntry2.getValue().getCount() > 1) {
            int count = cacheEntry2.getValue().getCount();
            cache = new CacheEntry(cacheEntry2.getValue().getRequest(), cacheEntry2.getValue().getResponse(), cacheEntry2.getValue().getDiagnosis(), cacheEntry2.getValue().getSessionFirstPacket());
            cache.setHitCount(count);
            if (count > 2) {
                totalRequestResponseDupBytes += (cacheEntry2.getValue().getHttpRequestResponse().getContentLength() * (count - 1));
            } else {
                totalRequestResponseDupBytes += cacheEntry2.getValue().getHttpRequestResponse().getContentLength();
            }
            duplicateContent.add(cache);
        }
    }
    duplicateContentWithOriginals.addAll(dupsWithOrig);
    Collections.sort(duplicateContentWithOriginals);
    duplicateContentBytesRatio = totalRequestResponseBytes != 0 ? (double) totalRequestResponseDupBytes / totalRequestResponseBytes : 0.0;
    result.setCacheExpirationResponses(cacheExpirationResponses);
    result.setDiagnosisResults(diagnosisResults);
    result.setDuplicateContent(duplicateContent);
    result.setDuplicateContentBytesRatio(duplicateContentBytesRatio);
    result.setDuplicateContentWithOriginals(duplicateContentWithOriginals);
    result.setTotalRequestResponseBytes(totalRequestResponseBytes);
    result.setTotalRequestResponseDupBytes(totalRequestResponseDupBytes);
    GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsTimings(cacheAnalysisTitle, System.currentTimeMillis() - analysisStartTime, analysisCategory);
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SortedSet(java.util.SortedSet) DuplicateEntry(com.att.aro.core.packetanalysis.pojo.DuplicateEntry) ArrayList(java.util.ArrayList) List(java.util.List) Diagnosis(com.att.aro.core.packetanalysis.pojo.Diagnosis) CacheExpiration(com.att.aro.core.packetanalysis.pojo.CacheExpiration) HashSet(java.util.HashSet) HttpRequestResponseInfoWithSession(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfoWithSession) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) CacheEntry(com.att.aro.core.packetanalysis.pojo.CacheEntry) Range(com.att.aro.core.packetanalysis.pojo.Range) CacheAnalysis(com.att.aro.core.packetanalysis.pojo.CacheAnalysis) ICacheAnalysis(com.att.aro.core.packetanalysis.ICacheAnalysis) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) HttpRequestResponseInfoWithSession(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfoWithSession) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 3 with CacheAnalysis

use of com.att.aro.core.packetanalysis.pojo.CacheAnalysis in project VideoOptimzer by attdevsupport.

the class HTTPCacheStatistics method refresh.

@Override
public void refresh(AROTraceData model) {
    PacketAnalyzerResult analyzerResult = model.getAnalyzerResult();
    CacheAnalysis cacheAnalysis = analyzerResult.getCacheAnalysis();
    Statistic statistic = analyzerResult.getStatistic();
    List<Session> sessions = analyzerResult.getSessionlist();
    if (cacheAnalysis != null && statistic != null && sessions != null) {
        CacheAnalysisDerived cacheAnalysisDerived = new CacheAnalysisDerived(cacheAnalysis, statistic, sessions);
        refreshLine(LabelKeys.cache_cacheable, cacheAnalysisDerived.getPctCacheableResponses(), cacheAnalysisDerived.getPctCacheableBytes());
        refreshLine(LabelKeys.cache_nonCachable, cacheAnalysisDerived.getPctNonCacheableResponses(), cacheAnalysisDerived.getPctNonCacheableBytes());
        refreshLine(LabelKeys.cache_cacheMiss, cacheAnalysisDerived.getPctCacheMissResponses(), cacheAnalysisDerived.getPctCacheMissBytes());
        refreshLine(LabelKeys.cache_notCacheable, cacheAnalysisDerived.getPctNotCacheableResponses(), cacheAnalysisDerived.getPctNotCacheableBytes());
        refreshLine(LabelKeys.cache_cacheHitExpiredDup304, cacheAnalysisDerived.getPctExpiredResponses(), cacheAnalysisDerived.getPctExpiredBytes());
        refreshLine(LabelKeys.cache_cacheHitRespChanged, cacheAnalysisDerived.getPctNotExpiredResponses(), cacheAnalysisDerived.getPctNotExpiredBytes());
        refreshLine(LabelKeys.cache_cacheHitNotExpiredDup, cacheAnalysisDerived.getPctCacheMissResponses(), cacheAnalysisDerived.getPctCacheMissBytes());
        refreshLine(LabelKeys.cache_cacheHitExpiredClientDup, cacheAnalysisDerived.getPctNotCacheableResponses(), cacheAnalysisDerived.getPctNotCacheableBytes());
        refreshLine(LabelKeys.cache_cacheHitExpiredServerDup, cacheAnalysisDerived.getPctCacheHitNotExpiredDupResponses(), cacheAnalysisDerived.getPctCacheHitNotExpiredDupBytes());
        refreshLine(LabelKeys.cache_partialHitNotExpiredDup, cacheAnalysisDerived.getPctCacheHitRespChangedResponses(), cacheAnalysisDerived.getPctCacheHitRespChangedBytes());
        refreshLine(LabelKeys.cache_partialHitExpiredClientDup, cacheAnalysisDerived.getPctCacheHitExpiredDupClientResponses(), cacheAnalysisDerived.getPctCacheHitExpiredDupClientBytes());
        refreshLine(LabelKeys.cache_partialHitExpiredServerDup, cacheAnalysisDerived.getPctCacheHitExpiredDupServerResponses(), cacheAnalysisDerived.getPctCacheHitExpiredDupServerBytes());
        refreshLine(LabelKeys.cache_notExpired, cacheAnalysisDerived.getPctCacheHitDup304Responses(), cacheAnalysisDerived.getPctCacheHitDup304Bytes());
        refreshLine(LabelKeys.cache_notExpiredHeur, cacheAnalysisDerived.getPctPartialHitExpiredDupClientResponses(), cacheAnalysisDerived.getPctPartialHitExpiredDupClientBytes());
        refreshLine(LabelKeys.cache_expired, cacheAnalysisDerived.getPctPartialHitExpiredDupServerResponses(), cacheAnalysisDerived.getPctPartialHitExpiredDupServerBytes());
        refreshLine(LabelKeys.cache_expiredHeur, cacheAnalysisDerived.getPctPartialHitNotExpiredDupResponses(), cacheAnalysisDerived.getPctPartialHitNotExpiredDupBytes());
    }
}
Also used : Statistic(com.att.aro.core.packetanalysis.pojo.Statistic) CacheAnalysis(com.att.aro.core.packetanalysis.pojo.CacheAnalysis) CacheAnalysisDerived(com.att.aro.ui.view.statistics.model.CacheAnalysisDerived) PacketAnalyzerResult(com.att.aro.core.packetanalysis.pojo.PacketAnalyzerResult) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 4 with CacheAnalysis

use of com.att.aro.core.packetanalysis.pojo.CacheAnalysis in project VideoOptimzer by attdevsupport.

the class AROServiceImplTest method analyzeDirectoryTest.

@Test
public void analyzeDirectoryTest() throws IOException {
    TraceDirectoryResult traceresult = new TraceDirectoryResult();
    List<PacketInfo> allpackets = new ArrayList<PacketInfo>();
    allpackets.add(new PacketInfo(new Packet(0, 0, 0, 0, null)));
    traceresult.setAllpackets(allpackets);
    PacketAnalyzerResult analyze = new PacketAnalyzerResult();
    analyze.setTraceresult(traceresult);
    CacheAnalysis cacheAnalysis = new CacheAnalysis();
    PeriodicTransferResult periodicTransferResult = new PeriodicTransferResult();
    List<BestPracticeType> req = new ArrayList<BestPracticeType>();
    req.add(BestPracticeType.UNNECESSARY_CONNECTIONS);
    req.add(BestPracticeType.CONNECTION_CLOSING);
    req.add(BestPracticeType.CONNECTION_OPENING);
    req.add(BestPracticeType.PERIODIC_TRANSFER);
    req.add(BestPracticeType.SCREEN_ROTATION);
    req.add(BestPracticeType.ACCESSING_PERIPHERALS);
    req.add(BestPracticeType.COMBINE_CS_JSS);
    req.add(BestPracticeType.HTTP_1_0_USAGE);
    req.add(BestPracticeType.CACHE_CONTROL);
    req.add(BestPracticeType.USING_CACHE);
    req.add(BestPracticeType.DUPLICATE_CONTENT);
    req.add(BestPracticeType.HTTP_4XX_5XX);
    req.add(BestPracticeType.HTTP_3XX_CODE);
    req.add(BestPracticeType.FILE_COMPRESSION);
    req.add(BestPracticeType.IMAGE_SIZE);
    req.add(BestPracticeType.MINIFICATION);
    req.add(BestPracticeType.EMPTY_URL);
    req.add(BestPracticeType.SPRITEIMAGE);
    req.add(BestPracticeType.SCRIPTS_URL);
    req.add(BestPracticeType.ASYNC_CHECK);
    req.add(BestPracticeType.DISPLAY_NONE_IN_CSS);
    req.add(BestPracticeType.FILE_ORDER);
    req.add(BestPracticeType.VIDEO_STALL);
    req.add(BestPracticeType.STARTUP_DELAY);
    req.add(BestPracticeType.BUFFER_OCCUPANCY);
    req.add(BestPracticeType.NETWORK_COMPARISON);
    req.add(BestPracticeType.TCP_CONNECTION);
    req.add(BestPracticeType.CHUNK_SIZE);
    req.add(BestPracticeType.CHUNK_PACING);
    req.add(BestPracticeType.VIDEO_REDUNDANCY);
    req.add(BestPracticeType.VIDEO_VARIABLE_BITRATE);
    req.add(BestPracticeType.HTTPS_USAGE);
    req.add(BestPracticeType.TRANSMISSION_PRIVATE_DATA);
    req.add(BestPracticeType.DISPLAY_NONE_IN_CSS);
    req.add(BestPracticeType.VIDEO_CONCURRENT_SESSION);
    req.add(BestPracticeType.AUDIO_STREAM);
    req.add(BestPracticeType.MULTI_SIMULCONN);
    List<BestPracticeType> list = SettingsUtil.retrieveBestPractices();
    SettingsUtil.saveBestPractices(req);
    when(packetanalyzer.analyzeTraceDirectory(any(String.class), any(Profile.class), any(AnalysisFilter.class))).thenReturn(analyze);
    when(worker.runTest(any(PacketAnalyzerResult.class))).thenReturn(periodicTransferResult);
    when(cacheAnalyzer.analyze(anyListOf(Session.class))).thenReturn(cacheAnalysis);
    try {
        AROTraceData testResult = aro.analyzeDirectory(req, Util.getCurrentRunningDir());
        assertEquals(null, testResult.getBestPracticeResults());
    } finally {
        SettingsUtil.saveBestPractices(list);
    }
}
Also used : Packet(com.att.aro.core.packetreader.pojo.Packet) PeriodicTransferResult(com.att.aro.core.bestpractice.pojo.PeriodicTransferResult) AnalysisFilter(com.att.aro.core.packetanalysis.pojo.AnalysisFilter) ArrayList(java.util.ArrayList) BestPracticeType(com.att.aro.core.bestpractice.pojo.BestPracticeType) AROTraceData(com.att.aro.core.pojo.AROTraceData) Profile(com.att.aro.core.configuration.pojo.Profile) CacheAnalysis(com.att.aro.core.packetanalysis.pojo.CacheAnalysis) ICacheAnalysis(com.att.aro.core.packetanalysis.ICacheAnalysis) TraceDirectoryResult(com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) PacketAnalyzerResult(com.att.aro.core.packetanalysis.pojo.PacketAnalyzerResult) Session(com.att.aro.core.packetanalysis.pojo.Session) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Example 5 with CacheAnalysis

use of com.att.aro.core.packetanalysis.pojo.CacheAnalysis in project VideoOptimzer by attdevsupport.

the class CacheAnalysisImplTest method analyze_2.

@Test
public void analyze_2() {
    List<PacketInfo> packets = new ArrayList<PacketInfo>();
    pktInfo01 = Mockito.mock(PacketInfo.class);
    pktInfo02 = Mockito.mock(PacketInfo.class);
    for (int i = 0; i < 60; i++) {
        httpRequestInfoArray[i] = mock(HttpRequestResponseInfo.class);
    }
    for (int i = 0; i < 20; i++) {
        when(httpRequestInfoArray[i].isNoStore()).thenReturn(true);
        if (i % 2 == 1) {
            when(httpRequestInfoArray[i].getDirection()).thenReturn(HttpDirection.REQUEST);
            when(httpRequestInfoArray[i].getHostName()).thenReturn("www.google.com");
            when(httpRequestInfoArray[i].getObjName()).thenReturn(Util.getCurrentRunningDir());
            when(httpRequestInfoArray[i].getContentLength()).thenReturn(5);
        } else {
            when(httpRequestInfoArray[i].getDirection()).thenReturn(HttpDirection.RESPONSE);
            when(httpRequestInfoArray[18].getStatusCode()).thenReturn(304);
        }
    }
    for (int i = 20; i < 60; i++) {
        when(httpRequestInfoArray[i].isNoStore()).thenReturn(false);
        when(httpRequestInfoArray[i].getHostName()).thenReturn("www.google.com" + i);
        when(httpRequestInfoArray[i].getObjName()).thenReturn(Util.getCurrentRunningDir());
        when(httpRequestInfoArray[i - 2].isRangeResponse()).thenReturn(true);
        when(httpRequestInfoArray[i].getContentLength()).thenReturn(5);
        if ((i - 20) % 2 == 1) {
            when(httpRequestInfoArray[i].getDirection()).thenReturn(HttpDirection.REQUEST);
        } else {
            when(httpRequestInfoArray[i].getDirection()).thenReturn(HttpDirection.RESPONSE);
            when(httpRequestInfoArray[i].getStatusCode()).thenReturn(206);
        }
    }
    when(httpRequestInfoArray[2].getAssocReqResp()).thenReturn(null);
    when(httpRequestInfoArray[4].getAssocReqResp()).thenReturn(httpRequestInfoArray[3]);
    when(httpRequestInfoArray[6].getAssocReqResp()).thenReturn(httpRequestInfoArray[5]);
    when(httpRequestInfoArray[8].getAssocReqResp()).thenReturn(httpRequestInfoArray[7]);
    when(httpRequestInfoArray[10].getAssocReqResp()).thenReturn(httpRequestInfoArray[9]);
    when(httpRequestInfoArray[12].getAssocReqResp()).thenReturn(httpRequestInfoArray[11]);
    when(httpRequestInfoArray[14].getAssocReqResp()).thenReturn(httpRequestInfoArray[13]);
    for (int i = 18; i < 60; i++) {
        when(httpRequestInfoArray[i].getAssocReqResp()).thenReturn(httpRequestInfoArray[i - 1]);
    }
    for (int i = 50; i < 60; i++) {
        when(httpRequestInfoArray[i].isRangeResponse()).thenReturn(false);
        when(httpRequestInfoArray[i].isChunked()).thenReturn(true);
        when(httpRequestInfoArray[i].getContentLength()).thenReturn(5);
    }
    for (int i = 0; i < 50; i++) {
        when(httpRequestInfoArray[i].isRangeResponse()).thenReturn(true);
    }
    when(httpRequestInfoArray[7].getHostName()).thenReturn(null);
    when(httpRequestInfoArray[7].getObjName()).thenReturn(null);
    when(httpRequestInfoArray[0].getStatusCode()).thenReturn(0);
    when(httpRequestInfoArray[2].getStatusCode()).thenReturn(200);
    when(httpRequestInfoArray[4].getStatusCode()).thenReturn(200);
    when(httpRequestInfoArray[6].getStatusCode()).thenReturn(200);
    when(httpRequestInfoArray[8].getStatusCode()).thenReturn(206);
    when(httpRequestInfoArray[10].getStatusCode()).thenReturn(206);
    when(httpRequestInfoArray[12].getStatusCode()).thenReturn(206);
    when(httpRequestInfoArray[14].getStatusCode()).thenReturn(304);
    when(httpRequestInfoArray[16].getStatusCode()).thenReturn(304);
    when(httpRequestInfoArray[18].getStatusCode()).thenReturn(304);
    when(httpRequestInfoArray[1].getRequestType()).thenReturn(HttpRequestResponseInfo.UTF8);
    when(httpRequestInfoArray[3].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_POST);
    when(httpRequestInfoArray[5].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_PUT);
    when(httpRequestInfoArray[7].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
    when(httpRequestInfoArray[9].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_POST);
    when(httpRequestInfoArray[11].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
    when(httpRequestInfoArray[13].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
    when(httpRequestInfoArray[15].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_POST);
    when(httpRequestInfoArray[17].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_PUT);
    when(httpRequestInfoArray[19].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_PUT);
    when(httpRequestInfoArray[20].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
    when(httpRequestInfoArray[21].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
    for (int i = 22; i < 60; i++) {
        if (i % 2 == 1) {
            when(httpRequestInfoArray[i].getRequestType()).thenReturn(HttpRequestResponseInfo.HTTP_GET);
        }
    }
    // Friday, January 16, 2015
    Date date01 = new Date(1421384400000L);
    // 5:00:00 AM GMT
    Date date02 = new Date(1421384400000L - 76400000L);
    Date date03 = new Date(1421384400000L - 86400000L);
    Date date04 = new Date(1421383400000L - 176400000L);
    for (int i = 0; i < 60; i++) {
        when(httpRequestInfoArray[i].getMaxAge()).thenReturn(86400000L);
    }
    for (int i = 0; i < 60; i++) {
        if (i % 2 == 1) {
            when(httpRequestInfoArray[i].getExpires()).thenReturn(date03);
            when(httpRequestInfoArray[i].getDate()).thenReturn(date02);
            when(httpRequestInfoArray[i].getAbsTimeStamp()).thenReturn(date02);
            when(httpRequestInfoArray[i].getLastModified()).thenReturn(date);
        } else {
            if (i < 40) {
                when(httpRequestInfoArray[i].getLastModified()).thenReturn(date01);
                when(httpRequestInfoArray[i].getRangeFirst()).thenReturn(0);
                when(httpRequestInfoArray[i].getRangeLast()).thenReturn(5);
                when(httpRequestInfoArray[i].getAbsTimeStamp()).thenReturn(date02);
                when(httpRequestInfoArray[i].getExpires()).thenReturn(date);
                when(httpRequestInfoArray[i].getDate()).thenReturn(date03);
            } else {
                when(httpRequestInfoArray[i].getLastModified()).thenReturn(date02);
                when(httpRequestInfoArray[i].getExpires()).thenReturn(date04);
                when(httpRequestInfoArray[i].getDate()).thenReturn(date);
                when(httpRequestInfoArray[i].getAbsTimeStamp()).thenReturn(date);
                when(httpRequestInfoArray[i].getRangeFirst()).thenReturn(0);
                when(httpRequestInfoArray[i].getRangeLast()).thenReturn(13);
            }
        }
    }
    when(httpRequestInfoArray[30].isRangeResponse()).thenReturn(false);
    when(httpRequestInfoArray[31].isRangeResponse()).thenReturn(false);
    when(rrhelper.getActualByteCount(any(HttpRequestResponseInfo.class), any(Session.class))).thenReturn(2L);
    List<HttpRequestResponseInfo> value = new ArrayList<HttpRequestResponseInfo>();
    for (int i = 0; i < 60; i++) {
        value.add(httpRequestInfoArray[i]);
    }
    packets.add(pktInfo01);
    packets.add(pktInfo02);
    when(session01.getRequestResponseInfo()).thenReturn(value);
    when(session01.isUdpOnly()).thenReturn(false);
    when(session01.getTcpPackets()).thenReturn(packets);
    when(session02.isUdpOnly()).thenReturn(false);
    when(session02.getRequestResponseInfo()).thenReturn(value);
    when(session02.getTcpPackets()).thenReturn(packets);
    List<Session> sessionList = new ArrayList<Session>();
    sessionList.add(session01);
    sessionList.add(session02);
    CacheAnalysis testResult = cacheAnalysis.analyze(sessionList);
    assertEquals(4, testResult.getCacheExpirationResponses().size());
    assertEquals(60, testResult.getDiagnosisResults().size());
    assertEquals(95, testResult.getDuplicateContentBytes());
    assertEquals(0.475, testResult.getDuplicateContentBytesRatio(), 0.225);
    assertEquals(38, testResult.getDuplicateContentWithOriginals().size());
}
Also used : CacheAnalysis(com.att.aro.core.packetanalysis.pojo.CacheAnalysis) ICacheAnalysis(com.att.aro.core.packetanalysis.ICacheAnalysis) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) ArrayList(java.util.ArrayList) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) Date(java.util.Date) Session(com.att.aro.core.packetanalysis.pojo.Session) Test(org.junit.Test) BaseTest(com.att.aro.core.BaseTest)

Aggregations

CacheAnalysis (com.att.aro.core.packetanalysis.pojo.CacheAnalysis)6 Session (com.att.aro.core.packetanalysis.pojo.Session)5 ICacheAnalysis (com.att.aro.core.packetanalysis.ICacheAnalysis)4 PacketInfo (com.att.aro.core.packetanalysis.pojo.PacketInfo)4 ArrayList (java.util.ArrayList)4 BaseTest (com.att.aro.core.BaseTest)3 HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)3 Test (org.junit.Test)3 CacheEntry (com.att.aro.core.packetanalysis.pojo.CacheEntry)2 PacketAnalyzerResult (com.att.aro.core.packetanalysis.pojo.PacketAnalyzerResult)2 Date (java.util.Date)2 BestPracticeType (com.att.aro.core.bestpractice.pojo.BestPracticeType)1 DuplicateContentResult (com.att.aro.core.bestpractice.pojo.DuplicateContentResult)1 PeriodicTransferResult (com.att.aro.core.bestpractice.pojo.PeriodicTransferResult)1 Profile (com.att.aro.core.configuration.pojo.Profile)1 AnalysisFilter (com.att.aro.core.packetanalysis.pojo.AnalysisFilter)1 CacheExpiration (com.att.aro.core.packetanalysis.pojo.CacheExpiration)1 Diagnosis (com.att.aro.core.packetanalysis.pojo.Diagnosis)1 DuplicateEntry (com.att.aro.core.packetanalysis.pojo.DuplicateEntry)1 HttpRequestResponseInfoWithSession (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfoWithSession)1