You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2019/04/10 20:48:36 UTC

[trafficserver] branch master updated: Adds cache alterante update tests

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

bcall 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 6406ef8  Adds cache alterante update tests
6406ef8 is described below

commit 6406ef8c66b3dd009af3e2f2b8f3cd6e409fa2cf
Author: scw00 <sc...@apache.org>
AuthorDate: Wed Apr 10 01:46:00 2019 +0000

    Adds cache alterante update tests
---
 iocore/cache/Makefile.am                |  18 +++-
 iocore/cache/test/main.cc               |   7 +-
 iocore/cache/test/main.h                |   1 +
 iocore/cache/test/test_Update_L_to_S.cc | 155 ++++++++++++++++++++++++++++++++
 iocore/cache/test/test_Update_S_to_L.cc | 155 ++++++++++++++++++++++++++++++++
 5 files changed, 334 insertions(+), 2 deletions(-)

diff --git a/iocore/cache/Makefile.am b/iocore/cache/Makefile.am
index a9993a3..b5d7c5d 100644
--- a/iocore/cache/Makefile.am
+++ b/iocore/cache/Makefile.am
@@ -127,7 +127,9 @@ check_PROGRAMS = \
   test_Alternate_L_to_S_remove_L \
   test_Alternate_L_to_S_remove_S \
   test_Alternate_S_to_L_remove_S \
-  test_Alternate_S_to_L_remove_L
+  test_Alternate_S_to_L_remove_L \
+  test_Update_L_to_S \
+  test_Update_S_to_L
 
 test_main_SOURCES = \
   ./test/main.cc \
@@ -190,6 +192,20 @@ test_Alternate_S_to_L_remove_L_SOURCES = \
   $(test_main_SOURCES) \
   ./test/test_Alternate_S_to_L_remove_L.cc
 
+test_Update_L_to_S_CPPFLAGS = $(test_CPPFLAGS)
+test_Update_L_to_S_LDFLAGS = @AM_LDFLAGS@
+test_Update_L_to_S_LDADD = $(test_LDADD)
+test_Update_L_to_S_SOURCES = \
+  $(test_main_SOURCES) \
+  ./test/test_Update_L_to_S.cc
+
+test_Update_S_to_L_CPPFLAGS = $(test_CPPFLAGS)
+test_Update_S_to_L_LDFLAGS = @AM_LDFLAGS@
+test_Update_S_to_L_LDADD = $(test_LDADD)
+test_Update_S_to_L_SOURCES = \
+  $(test_main_SOURCES) \
+  ./test/test_Update_S_to_L.cc
+
 include $(top_srcdir)/build/tidy.mk
 
 clang-tidy-local: $(DIST_SOURCES)
diff --git a/iocore/cache/test/main.cc b/iocore/cache/test/main.cc
index a553940..c9427c4 100644
--- a/iocore/cache/test/main.cc
+++ b/iocore/cache/test/main.cc
@@ -204,8 +204,13 @@ CacheWriteTest::start_test(int event, void *e)
   HttpCacheKey key;
   key = generate_key(this->info);
 
+  HTTPInfo *old_info = &this->old_info;
+  if (!old_info->valid()) {
+    old_info = nullptr;
+  }
+
   SET_HANDLER(&CacheWriteTest::write_event);
-  cacheProcessor.open_write(this, 0, &key, (CacheHTTPHdr *)this->info.request_get(), nullptr);
+  cacheProcessor.open_write(this, 0, &key, (CacheHTTPHdr *)this->info.request_get(), old_info);
   return 0;
 }
 
diff --git a/iocore/cache/test/main.h b/iocore/cache/test/main.h
index e661faa..5bcc4f8 100644
--- a/iocore/cache/test/main.h
+++ b/iocore/cache/test/main.h
@@ -197,6 +197,7 @@ public:
   void do_io_write(size_t size = 0) override;
 
   HTTPInfo info;
+  HTTPInfo old_info;
 
 private:
   size_t _size             = 0;
diff --git a/iocore/cache/test/test_Update_L_to_S.cc b/iocore/cache/test/test_Update_L_to_S.cc
new file mode 100644
index 0000000..1172c81
--- /dev/null
+++ b/iocore/cache/test/test_Update_L_to_S.cc
@@ -0,0 +1,155 @@
+/** @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()
+  {
+    this->_rt        = new CacheReadTest(size, this, url);
+    this->_rt->mutex = this->mutex;
+
+    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();
+      break;
+    case VC_EVENT_READ_READY:
+      base->reenable();
+      break;
+    case VC_EVENT_READ_COMPLETE:
+      base->close();
+      delete this;
+      break;
+    default:
+      REQUIRE(false);
+      break;
+    }
+  }
+};
+
+class CacheUpdate_L_to_S : public CacheTestHandler
+{
+public:
+  CacheUpdate_L_to_S(size_t read_size, size_t write_size, const char *url)
+  {
+    this->_rt = new CacheReadTest(read_size, this, url);
+    this->_wt = new CacheWriteTest(write_size, this, url);
+
+    this->_rt->mutex = this->mutex;
+    this->_wt->mutex = this->mutex;
+
+    SET_HANDLER(&CacheUpdate_L_to_S::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();
+      break;
+    case VC_EVENT_WRITE_READY:
+      base->reenable();
+      break;
+    case VC_EVENT_WRITE_COMPLETE:
+      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");
+    CacheUpdate_L_to_S *update = new CacheUpdate_L_to_S(LARGE_FILE, SMALL_FILE, "http://www.scw11.com");
+    CacheUpdateReadAgain *read = new CacheUpdateReadAgain(SMALL_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();
+}
diff --git a/iocore/cache/test/test_Update_S_to_L.cc b/iocore/cache/test/test_Update_S_to_L.cc
new file mode 100644
index 0000000..2944c33
--- /dev/null
+++ b/iocore/cache/test/test_Update_S_to_L.cc
@@ -0,0 +1,155 @@
+/** @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()
+  {
+    this->_rt        = new CacheReadTest(size, this, url);
+    this->_rt->mutex = this->mutex;
+
+    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();
+      break;
+    case VC_EVENT_READ_READY:
+      base->reenable();
+      break;
+    case VC_EVENT_READ_COMPLETE:
+      base->close();
+      delete this;
+      break;
+    default:
+      REQUIRE(false);
+      break;
+    }
+  }
+};
+
+class CacheUpdate_S_to_L : public CacheTestHandler
+{
+public:
+  CacheUpdate_S_to_L(size_t read_size, size_t write_size, const char *url)
+  {
+    this->_rt = new CacheReadTest(read_size, this, url);
+    this->_wt = new CacheWriteTest(write_size, this, url);
+
+    this->_rt->mutex = this->mutex;
+    this->_wt->mutex = this->mutex;
+
+    SET_HANDLER(&CacheUpdate_S_to_L::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();
+      break;
+    case VC_EVENT_WRITE_READY:
+      base->reenable();
+      break;
+    case VC_EVENT_WRITE_COMPLETE:
+      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(SMALL_FILE, "http://www.scw11.com");
+    CacheUpdate_S_to_L *update = new CacheUpdate_S_to_L(SMALL_FILE, 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();
+}