diff options
author | Giuseppe Castagno <giuseppe.castagno@acca-esse.eu> | 2016-08-20 15:45:07 +0200 |
---|---|---|
committer | Giuseppe Castagno <giuseppe.castagno@acca-esse.eu> | 2016-08-23 10:36:39 +0000 |
commit | 98bd24f8b479132ca3f2d884749b738e9e6203e3 (patch) | |
tree | 396088188267e6f8f189494c095f8315329af70c /ucb/qa | |
parent | 2b4d13f135cd0e0b7000f1de658c35c873f533b3 (diff) |
Related: tdf#82677, implement a PROPFIND 'propname' request cache
PROPFIND 'propname' is the special usage to retrieve all the
properties available on the URI resource, their names only.
See <https://tools.ietf.org/html/rfc4918#section-9.1> for
PROPFIND 'propname' definition.
Add cache usage in Content::getProperties as well.
The caching model is simple: a simple lifetime limit of 10 seconds
to declare the property name list stale and request another list,
accessing the Net.
This should reduce the number of PROPFIND calls on the Net.
Change-Id: Ie4ebd946dd81583dc964a62c7744f3e2c716c737
Reviewed-on: https://gerrit.libreoffice.org/28273
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Giuseppe Castagno <giuseppe.castagno@acca-esse.eu>
Diffstat (limited to 'ucb/qa')
-rw-r--r-- | ucb/qa/cppunit/webdav/webdav_options.cxx | 1 | ||||
-rw-r--r-- | ucb/qa/cppunit/webdav/webdav_propfindcache.cxx | 136 |
2 files changed, 136 insertions, 1 deletions
diff --git a/ucb/qa/cppunit/webdav/webdav_options.cxx b/ucb/qa/cppunit/webdav/webdav_options.cxx index 6c896232b816..bad3adc8da77 100644 --- a/ucb/qa/cppunit/webdav/webdav_options.cxx +++ b/ucb/qa/cppunit/webdav/webdav_options.cxx @@ -11,7 +11,6 @@ #include <cppunit/plugin/TestPlugIn.h> #include "DAVTypes.hxx" - namespace { diff --git a/ucb/qa/cppunit/webdav/webdav_propfindcache.cxx b/ucb/qa/cppunit/webdav/webdav_propfindcache.cxx new file mode 100644 index 000000000000..074f21d31eef --- /dev/null +++ b/ucb/qa/cppunit/webdav/webdav_propfindcache.cxx @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/bootstrapfixture.hxx> +#include <cppunit/plugin/TestPlugIn.h> +#include <cmath> +#include "PropfindCache.hxx" + +using namespace webdav_ucp; + +namespace +{ + + class webdav_propcache_test: public test::BootstrapFixture + { + + public: + webdav_propcache_test() : BootstrapFixture( true, true ) {} + + // initialise your test code values here. + void setUp( ) override; + + void tearDown( ) override; + + void PropfindCacheElemTests(); + void PropfindCacheTests(); + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE( webdav_propcache_test ); + CPPUNIT_TEST( PropfindCacheElemTests ); + CPPUNIT_TEST( PropfindCacheTests ); + CPPUNIT_TEST_SUITE_END(); + }; // class webdav_local_test + + // initialise your test code values here. + void webdav_propcache_test::setUp() + { + } + + void webdav_propcache_test::tearDown() + { + } + + void webdav_propcache_test::PropfindCacheElemTests( ) + { + OUString aTheURL( "http:://server/path/filename.odt" ); + PropertyNames aPropsNames( aTheURL ); + + CPPUNIT_ASSERT_EQUAL( aTheURL, aPropsNames.getURL() ); + CPPUNIT_ASSERT_EQUAL( static_cast< sal_uInt32 >(0), aPropsNames.getStaleTime() ); + + sal_uInt32 maxTime = static_cast< sal_uInt32 >(std::pow(2,32)-1); + + aPropsNames.setStaleTime( maxTime ); + CPPUNIT_ASSERT_EQUAL( maxTime, aPropsNames.getStaleTime() ); + + std::vector < OUString > properties { + "DAV:lockdiscovery", + "DAV:supportedlock", + "DAV:resourcetype", + "DAV:displayname", + "DAV:getlastmodified", + "DAV:getcontentlength", + "DAV:creationdate", + "DAV:getetag", + "DAV:authticket", + }; + + DAVResourceInfo aSingleInfo { properties }; + std::vector< DAVResourceInfo > aProps { aSingleInfo }; + std::vector< DAVResourceInfo > aRetProp; + + aPropsNames.setPropertiesNames( aProps ); + aRetProp = aPropsNames.getPropertiesNames(); + CPPUNIT_ASSERT_EQUAL( true, ( aProps == aRetProp ) ); + + aProps[0].properties.push_back( "DAV:getlastmodified" ); + aRetProp = aPropsNames.getPropertiesNames(); + CPPUNIT_ASSERT_EQUAL( false, ( aProps == aRetProp ) ); + } + + void webdav_propcache_test::PropfindCacheTests( ) + { + PropertyNamesCache PropCache; + OUString aTheURL( "http:://server/path/filename.odt" ); + PropertyNames aPropsNames( aTheURL ); + + // check cache emptiness + CPPUNIT_ASSERT_EQUAL( false, PropCache.getCachedPropertyNames( aTheURL, aPropsNames ) ); + + std::vector < OUString > properties { + "DAV:lockdiscovery", + "DAV:supportedlock", + "DAV:resourcetype", + "DAV:displayname", + "DAV:getlastmodified", + "DAV:getcontentlength", + "DAV:creationdate", + "DAV:getetag", + "DAV:authticket", + }; + + DAVResourceInfo aSingleInfo { properties }; + std::vector< DAVResourceInfo > aProps { aSingleInfo }; + + // add the cache an element + aPropsNames.setPropertiesNames( aProps ); + PropCache.addCachePropertyNames( aPropsNames, 10 ); + + PropertyNames aRetPropsNames; + //test existence + CPPUNIT_ASSERT_EQUAL( true, PropCache.getCachedPropertyNames( aTheURL, aRetPropsNames ) ); + //check equality + std::vector< DAVResourceInfo > aRetProp = aRetPropsNames.getPropertiesNames(); + CPPUNIT_ASSERT_EQUAL( true, ( aProps == aRetProp ) ); + //remove from cache + PropCache.removeCachedPropertyNames( aTheURL ); + //check absence + CPPUNIT_ASSERT_EQUAL( false, PropCache.getCachedPropertyNames( aTheURL, aPropsNames ) ); + } + + CPPUNIT_TEST_SUITE_REGISTRATION( webdav_propcache_test ); +} // namespace rtl_random + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |