|
10 | 10 | use NCU\Config\Exceptions\TypeConflictException; |
11 | 11 | use NCU\Config\Exceptions\UnknownKeyException; |
12 | 12 | use NCU\Config\IUserConfig; |
| 13 | +use OC\AppConfig; |
13 | 14 | use OC\AppFramework\Bootstrap\Coordinator; |
| 15 | +use OC\Config\UserConfig; |
14 | 16 | use OCP\Exceptions\AppConfigTypeConflictException; |
15 | 17 | use OCP\Exceptions\AppConfigUnknownKeyException; |
16 | 18 | use OCP\IAppConfig; |
| 19 | +use OCP\IConfig; |
| 20 | +use OCP\IDBConnection; |
| 21 | +use OCP\Security\ICrypto; |
17 | 22 | use OCP\Server; |
| 23 | +use Psr\Log\LoggerInterface; |
18 | 24 | use Test\TestCase; |
19 | 25 |
|
20 | 26 | /** |
@@ -62,6 +68,80 @@ public function testAppLexiconSetCorrect() { |
62 | 68 | $this->appConfig->deleteKey(TestConfigLexicon_E::APPID, 'key1'); |
63 | 69 | } |
64 | 70 |
|
| 71 | + public function testAppConfigMigrationToLazy() { |
| 72 | + $app = TestConfigLexicon_Migration::APPID . '_app'; |
| 73 | + // to avoid filling cache with an empty Lexicon, we use a new IAppConfig |
| 74 | + $appConfig = new AppConfig( |
| 75 | + Server::get(IDBConnection::class), |
| 76 | + Server::get(LoggerInterface::class), |
| 77 | + Server::get(ICrypto::class), |
| 78 | + ); |
| 79 | + $this->assertSame(true, $appConfig->setValueString($app, 'key1', 'value1')); |
| 80 | + |
| 81 | + // confirm that key1 is not lazy, even after a refresh of the cache |
| 82 | + $appConfig->clearCache(); |
| 83 | + $this->assertSame('value1', $appConfig->getValueString($app, 'key1')); |
| 84 | + $this->assertSame(true, array_key_exists('key1', $appConfig->statusCache()['fastCache'][$app])); |
| 85 | + |
| 86 | + // loading new Lexicon that set key1 as lazy |
| 87 | + $bootstrapCoordinator = \OCP\Server::get(Coordinator::class); |
| 88 | + $bootstrapCoordinator->getRegistrationContext()?->registerConfigLexicon($app, TestConfigLexicon_Migration::class); |
| 89 | + |
| 90 | + // caching |
| 91 | + $this->assertSame('default0', $this->appConfig->getValueString($app, 'key0')); |
| 92 | + // still not lazy |
| 93 | + $this->assertSame(true, array_key_exists('key1', $this->appConfig->statusCache()['fastCache'][$app])); |
| 94 | + // trigger update of status |
| 95 | + $this->assertSame('value1', $this->appConfig->getValueString($app, 'key1')); |
| 96 | + // should be lazy now |
| 97 | + $this->assertSame(true, array_key_exists('key1', $this->appConfig->statusCache()['lazyCache'][$app])); |
| 98 | + |
| 99 | + $this->appConfig->clearCache(); |
| 100 | + $this->assertSame('default0', $this->appConfig->getValueString($app, 'key0')); |
| 101 | + // definitively lazy |
| 102 | + $this->assertSame(false, array_key_exists($app, $this->appConfig->statusCache()['fastCache'])); |
| 103 | + |
| 104 | + $this->appConfig->deleteKey($app, 'key1'); |
| 105 | + } |
| 106 | + |
| 107 | + public function testUserConfigMigrationToLazy() { |
| 108 | + $app = TestConfigLexicon_Migration::APPID . '_user'; |
| 109 | + // to avoid filling cache with an empty Lexicon, we use a new IAppConfig |
| 110 | + $userConfig = new UserConfig( |
| 111 | + Server::get(IDBConnection::class), |
| 112 | + Server::get(IConfig::class), |
| 113 | + Server::get(LoggerInterface::class), |
| 114 | + Server::get(ICrypto::class), |
| 115 | + ); |
| 116 | + $this->assertSame(true, $userConfig->setValueString('user1', $app, 'key1', 'value1')); |
| 117 | + |
| 118 | + // confirm that key1 is not lazy, even after a refresh of Lexicon |
| 119 | + $userConfig->clearCache('user1'); |
| 120 | + $this->assertSame('value1', $userConfig->getValueString('user1', $app, 'key1')); |
| 121 | + $this->assertSame(true, array_key_exists('key1', $userConfig->statusCache()['fastCache']['user1'][$app])); |
| 122 | + |
| 123 | + // loading new Lexicon that set key1 as lazy |
| 124 | + $bootstrapCoordinator = \OCP\Server::get(Coordinator::class); |
| 125 | + $bootstrapCoordinator->getRegistrationContext()?->registerConfigLexicon($app, TestConfigLexicon_Migration::class); |
| 126 | + |
| 127 | + // caching |
| 128 | + $this->assertSame('default0', $this->userConfig->getValueString('user1', $app, 'key0')); |
| 129 | + // still not lazy |
| 130 | + $this->assertSame(true, array_key_exists('key1', $this->userConfig->statusCache()['fastCache']['user1'][$app])); |
| 131 | + // trigger update of status |
| 132 | + $this->assertSame('value1', $this->userConfig->getValueString('user1', $app, 'key1')); |
| 133 | + // should be lazy now |
| 134 | + $this->assertSame(true, array_key_exists('key1', $this->userConfig->statusCache()['lazyCache']['user1'][$app])); |
| 135 | + |
| 136 | + $this->userConfig->clearCache('user1'); |
| 137 | + $this->assertSame('default0', $this->userConfig->getValueString('user1', $app, 'key0')); |
| 138 | + // definitively lazy |
| 139 | + $this->assertSame(false, array_key_exists($app, $this->userConfig->statusCache()['fastCache']['user1'])); |
| 140 | + |
| 141 | + $this->userConfig->deleteKey($app, 'key1'); |
| 142 | + } |
| 143 | + |
| 144 | + |
65 | 145 | public function testAppLexiconGetCorrect() { |
66 | 146 | $this->assertSame('abcde', $this->appConfig->getValueString(TestConfigLexicon_E::APPID, 'key1', 'default')); |
67 | 147 | } |
|
0 commit comments