You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by sc...@apache.org on 2019/05/07 03:38:50 UTC

[trafficserver] branch master updated: Adds update header only test case

This is an automated email from the ASF dual-hosted git repository.

scw00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new ee0ce71  Adds update header only test case
ee0ce71 is described below

commit ee0ce71fed73ae5092da12ced4e11556ecaced36
Author: scw00 <sc...@apache.org>
AuthorDate: Sat May 4 08:17:04 2019 +0000

    Adds update header only test case
---
 iocore/cache/Makefile.am                |  10 +-
 iocore/cache/test/test_Update_header.cc | 185 ++++++++++++++++++++++++++++++++
 2 files changed, 194 insertions(+), 1 deletion(-)

diff --git a/iocore/cache/Makefile.am b/iocore/cache/Makefile.am
index b2161f0..e9c9df3 100644
--- a/iocore/cache/Makefile.am
+++ b/iocore/cache/Makefile.am
@@ -128,7 +128,8 @@ check_PROGRAMS = \
   test_Alternate_S_to_L_remove_S \
   test_Alternate_S_to_L_remove_L \
   test_Update_L_to_S \
-  test_Update_S_to_L
+  test_Update_S_to_L \
+  test_Update_header
 
 test_main_SOURCES = \
   ./test/main.cc \
@@ -205,6 +206,13 @@ test_Update_S_to_L_SOURCES = \
   $(test_main_SOURCES) \
   ./test/test_Update_S_to_L.cc
 
+test_Update_header_CPPFLAGS = $(test_CPPFLAGS)
+test_Update_header_LDFLAGS = @AM_LDFLAGS@
+test_Update_header_LDADD = $(test_LDADD)
+test_Update_header_SOURCES = \
+  $(test_main_SOURCES) \
+  ./test/test_Update_header.cc
+
 include $(top_srcdir)/build/tidy.mk
 
 clang-tidy-local: $(DIST_SOURCES)
diff --git a/iocore/cache/test/test_Update_header.cc b/iocore/cache/test/test_Update_header.cc
new file mode 100644
index 0000000..7a69adb
--- /dev/null
+++ b/iocore/cache/test/test_Update_header.cc
@@ -0,0 +1,185 @@
+/** @file
+
+  A brief file description
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#define LARGE_FILE 10 * 1024 * 1024
+#define SMALL_FILE 10 * 1024
+
+#include "main.h"
+
+class CacheUpdateReadAgain : public CacheTestHandler
+{
+public:
+  CacheUpdateReadAgain(size_t size, const char *url) : CacheTestHandler()
+  {
+    auto rt   = new CacheReadTest(size, this, url);
+    rt->mutex = this->mutex;
+
+    rt->info.destroy();
+    rt->info.create();
+    build_hdrs(rt->info, url, "application/x-javascript");
+
+    this->_rt = rt;
+
+    SET_HANDLER(&CacheUpdateReadAgain::start_test);
+  }
+
+  int
+  start_test(int event, void *e)
+  {
+    REQUIRE(event == EVENT_IMMEDIATE);
+    this_ethread()->schedule_imm(this->_rt);
+    return 0;
+  }
+
+  virtual void
+  handle_cache_event(int event, CacheTestBase *base)
+  {
+    switch (event) {
+    case CACHE_EVENT_OPEN_READ:
+      base->do_io_read();
+      this->validate_content_type(base);
+      this->check_fragment_table(base);
+      break;
+    case VC_EVENT_READ_READY:
+      base->reenable();
+      break;
+    case VC_EVENT_READ_COMPLETE:
+      base->close();
+      delete this;
+      break;
+    default:
+      REQUIRE(false);
+      break;
+    }
+  }
+
+  void
+  validate_content_type(CacheTestBase *base)
+  {
+    auto rt = dynamic_cast<CacheReadTest *>(base);
+    REQUIRE(rt);
+    MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
+    REQUIRE(field);
+    int len;
+    const char *value = field->value_get(&len);
+    REQUIRE(memcmp(value, "application/x-javascript", len) == 0);
+  }
+
+  void
+  check_fragment_table(CacheTestBase *base)
+  {
+    REQUIRE(base->vc->alternate.get_frag_table() != nullptr);
+    REQUIRE(base->vc->alternate.get_frag_offset_count() != 0);
+  }
+};
+
+class CacheUpdateHeader : public CacheTestHandler
+{
+public:
+  CacheUpdateHeader(size_t read_size, const char *url)
+  {
+    auto rt = new CacheReadTest(read_size, this, url);
+    auto wt = new CacheWriteTest(read_size, this, url);
+
+    wt->info.destroy();
+    wt->info.create();
+    build_hdrs(wt->info, url, "application/x-javascript");
+
+    this->_rt = rt;
+    this->_wt = wt;
+
+    this->_rt->mutex = this->mutex;
+    this->_wt->mutex = this->mutex;
+
+    SET_HANDLER(&CacheUpdateHeader::start_test);
+  }
+
+  int
+  start_test(int event, void *e)
+  {
+    REQUIRE(event == EVENT_IMMEDIATE);
+    this_ethread()->schedule_imm(this->_rt);
+    return 0;
+  }
+
+  virtual void
+  handle_cache_event(int event, CacheTestBase *base)
+  {
+    CacheWriteTest *wt = static_cast<CacheWriteTest *>(this->_wt);
+    switch (event) {
+    case CACHE_EVENT_OPEN_WRITE:
+      base->do_io_write();
+      // commit the header change
+      this->_wt->close();
+      this->_wt = nullptr;
+      delete this;
+      break;
+    case CACHE_EVENT_OPEN_READ:
+      base->do_io_read();
+      wt->old_info.copy(static_cast<HTTPInfo *>(&base->vc->alternate));
+      break;
+    case VC_EVENT_READ_READY:
+      base->reenable();
+      break;
+    case VC_EVENT_READ_COMPLETE:
+      this->_rt->close();
+      this->_rt = nullptr;
+      this_ethread()->schedule_imm(this->_wt);
+      break;
+    default:
+      REQUIRE(false);
+      break;
+    }
+  }
+};
+
+class CacheUpdateInit : public CacheInit
+{
+public:
+  CacheUpdateInit() {}
+  int
+  cache_init_success_callback(int event, void *e) override
+  {
+    CacheTestHandler *h        = new CacheTestHandler(LARGE_FILE, "http://www.scw11.com");
+    CacheUpdateHeader *update  = new CacheUpdateHeader(LARGE_FILE, "http://www.scw11.com");
+    CacheUpdateReadAgain *read = new CacheUpdateReadAgain(LARGE_FILE, "http://www.scw11.com");
+    TerminalTest *tt           = new TerminalTest;
+
+    h->add(update);
+    h->add(read); // read again
+    h->add(tt);
+    this_ethread()->schedule_imm(h);
+    delete this;
+    return 0;
+  }
+};
+
+TEST_CASE("cache write -> read", "cache")
+{
+  init_cache(256 * 1024 * 1024);
+  // large write test
+  CacheUpdateInit *init = new CacheUpdateInit;
+
+  this_ethread()->schedule_imm(init);
+  this_thread()->execute();
+}