Commit 6d256576 authored by Van's avatar Van

Merge remote-tracking branch 'origin/2.9.5-dev' into 2.9.5-dev

parents deb301f3 139843ff
...@@ -41,12 +41,12 @@ public class ArticleCache { ...@@ -41,12 +41,12 @@ public class ArticleCache {
/** /**
* Article id cache. * Article id cache.
*/ */
private Map<String, JSONObject> idCache = new ConcurrentHashMap<>(); private final Map<String, JSONObject> idCache = new ConcurrentHashMap<>();
/** /**
* Article permalink cache. * Article permalink cache.
*/ */
private Map<String, JSONObject> permalinkCache = new ConcurrentHashMap<>(); private final Map<String, JSONObject> permalinkCache = new ConcurrentHashMap<>();
/** /**
* Gets an article by the specified article id. * Gets an article by the specified article id.
...@@ -98,7 +98,7 @@ public class ArticleCache { ...@@ -98,7 +98,7 @@ public class ArticleCache {
} }
/** /**
* Clears all cached articles. * Clears all cached data.
*/ */
public void clear() { public void clear() {
idCache.clear(); idCache.clear();
......
...@@ -40,7 +40,7 @@ public class CommentCache { ...@@ -40,7 +40,7 @@ public class CommentCache {
/** /**
* Comment cache. * Comment cache.
*/ */
private Map<String, JSONObject> cache = new ConcurrentHashMap<>(); private final Map<String, JSONObject> cache = new ConcurrentHashMap<>();
/** /**
* Gets a comment by the specified comment id. * Gets a comment by the specified comment id.
...@@ -76,7 +76,7 @@ public class CommentCache { ...@@ -76,7 +76,7 @@ public class CommentCache {
} }
/** /**
* Clears all cached comments. * Clears all cached data.
*/ */
public void clear() { public void clear() {
cache.clear(); cache.clear();
......
...@@ -41,12 +41,12 @@ public class OptionCache { ...@@ -41,12 +41,12 @@ public class OptionCache {
/** /**
* Option cache. * Option cache.
*/ */
private static final Map<String, JSONObject> CACHE = new ConcurrentHashMap<>(); private final Map<String, JSONObject> cache = new ConcurrentHashMap<>();
/** /**
* Category option caches. * Category option caches.
*/ */
private static final Map<String, JSONObject> CATEGORY_CACHES = new ConcurrentHashMap<>(); private final Map<String, JSONObject> categoryCache = new ConcurrentHashMap<>();
/** /**
* Removes a category cache specified by the given category. * Removes a category cache specified by the given category.
...@@ -54,7 +54,7 @@ public class OptionCache { ...@@ -54,7 +54,7 @@ public class OptionCache {
* @param category the given category * @param category the given category
*/ */
public void removeCategory(final String category) { public void removeCategory(final String category) {
CATEGORY_CACHES.remove(category); categoryCache.remove(category);
} }
/** /**
...@@ -64,7 +64,7 @@ public class OptionCache { ...@@ -64,7 +64,7 @@ public class OptionCache {
* @return merged options * @return merged options
*/ */
public JSONObject getCategory(final String category) { public JSONObject getCategory(final String category) {
JSONObject ret = CATEGORY_CACHES.get(category); JSONObject ret = categoryCache.get(category);
if (null == ret) { if (null == ret) {
return null; return null;
} }
...@@ -79,7 +79,7 @@ public class OptionCache { ...@@ -79,7 +79,7 @@ public class OptionCache {
* @param mergedOptions the specified merged options * @param mergedOptions the specified merged options
*/ */
public void putCategory(final String category, final JSONObject mergedOptions) { public void putCategory(final String category, final JSONObject mergedOptions) {
CATEGORY_CACHES.put(category, mergedOptions); categoryCache.put(category, mergedOptions);
} }
/** /**
...@@ -89,7 +89,7 @@ public class OptionCache { ...@@ -89,7 +89,7 @@ public class OptionCache {
* @return option, returns {@code null} if not found * @return option, returns {@code null} if not found
*/ */
public JSONObject getOption(final String id) { public JSONObject getOption(final String id) {
final JSONObject option = CACHE.get(id); final JSONObject option = cache.get(id);
if (null == option) { if (null == option) {
return null; return null;
} }
...@@ -103,7 +103,7 @@ public class OptionCache { ...@@ -103,7 +103,7 @@ public class OptionCache {
* @param option the specified option * @param option the specified option
*/ */
public void putOption(final JSONObject option) { public void putOption(final JSONObject option) {
CACHE.put(option.optString(Keys.OBJECT_ID), JSONs.clone(option)); cache.put(option.optString(Keys.OBJECT_ID), JSONs.clone(option));
final String category = option.optString(Option.OPTION_CATEGORY); final String category = option.optString(Option.OPTION_CATEGORY);
removeCategory(category); removeCategory(category);
...@@ -123,6 +123,14 @@ public class OptionCache { ...@@ -123,6 +123,14 @@ public class OptionCache {
final String category = option.optString(Option.OPTION_CATEGORY); final String category = option.optString(Option.OPTION_CATEGORY);
removeCategory(category); removeCategory(category);
CACHE.remove(id); cache.remove(id);
}
/**
* Clears all cached data.
*/
public void clear() {
cache.clear();
categoryCache.clear();
} }
} }
...@@ -40,7 +40,7 @@ public class PageCache { ...@@ -40,7 +40,7 @@ public class PageCache {
/** /**
* Page cache. * Page cache.
*/ */
private Map<String, JSONObject> cache = new ConcurrentHashMap<>(); private final Map<String, JSONObject> cache = new ConcurrentHashMap<>();
/** /**
* Gets a page by the specified page id. * Gets a page by the specified page id.
...@@ -76,4 +76,11 @@ public class PageCache { ...@@ -76,4 +76,11 @@ public class PageCache {
public void removePage(final String id) { public void removePage(final String id) {
cache.remove(id); cache.remove(id);
} }
/**
* Clears all cached data.
*/
public void clear() {
cache.clear();
}
} }
...@@ -39,7 +39,7 @@ public class StatisticCache { ...@@ -39,7 +39,7 @@ public class StatisticCache {
/** /**
* Statistic cache. * Statistic cache.
*/ */
private Map<String, JSONObject> cache = new ConcurrentHashMap<>(); private final Map<String, JSONObject> cache = new ConcurrentHashMap<>();
/** /**
* Get the statistic. * Get the statistic.
...@@ -60,7 +60,7 @@ public class StatisticCache { ...@@ -60,7 +60,7 @@ public class StatisticCache {
} }
/** /**
* Clears the statistic. * Clears all cached data.
*/ */
public void clear() { public void clear() {
cache.clear(); cache.clear();
......
...@@ -42,17 +42,17 @@ public class UserCache { ...@@ -42,17 +42,17 @@ public class UserCache {
/** /**
* Id, User. * Id, User.
*/ */
private Map<String, JSONObject> idCache = new ConcurrentHashMap<>(); private final Map<String, JSONObject> idCache = new ConcurrentHashMap<>();
/** /**
* Email, User. * Email, User.
*/ */
private Map<String, JSONObject> emailCache = new ConcurrentHashMap<>(); private final Map<String, JSONObject> emailCache = new ConcurrentHashMap<>();
/** /**
* Admin user. * Admin user.
*/ */
private Map<String, JSONObject> adminCache = new ConcurrentHashMap<>(); private final Map<String, JSONObject> adminCache = new ConcurrentHashMap<>();
/** /**
* Gets the admin user. * Gets the admin user.
...@@ -128,4 +128,13 @@ public class UserCache { ...@@ -128,4 +128,13 @@ public class UserCache {
final String email = user.optString(User.USER_EMAIL); final String email = user.optString(User.USER_EMAIL);
emailCache.remove(email); emailCache.remove(email);
} }
/**
* Clears all cached data.
*/
public void clear() {
idCache.clear();
emailCache.clear();
adminCache.clear();
}
} }
...@@ -443,7 +443,10 @@ public class LoginProcessor { ...@@ -443,7 +443,10 @@ public class LoginProcessor {
dataModel.put(Common.STATIC_RESOURCE_VERSION, Latkes.getStaticResourceVersion()); dataModel.put(Common.STATIC_RESOURCE_VERSION, Latkes.getStaticResourceVersion());
dataModel.put(Option.ID_C_BLOG_TITLE, preference.getString(Option.ID_C_BLOG_TITLE)); dataModel.put(Option.ID_C_BLOG_TITLE, preference.getString(Option.ID_C_BLOG_TITLE));
final String token = request.getParameter("token"); String token = request.getParameter("token");
if (StringUtils.isBlank(token)) {
token = "";
}
final JSONObject tokenObj = optionQueryService.getOptionById(token); final JSONObject tokenObj = optionQueryService.getOptionById(token);
if (tokenObj == null) { if (tokenObj == null) {
......
...@@ -24,9 +24,11 @@ import org.b3log.latke.ioc.config.Discoverer; ...@@ -24,9 +24,11 @@ import org.b3log.latke.ioc.config.Discoverer;
import org.b3log.latke.repository.jdbc.util.Connections; import org.b3log.latke.repository.jdbc.util.Connections;
import org.b3log.latke.repository.jdbc.util.JdbcRepositories; import org.b3log.latke.repository.jdbc.util.JdbcRepositories;
import org.b3log.solo.api.metaweblog.MetaWeblogAPI; import org.b3log.solo.api.metaweblog.MetaWeblogAPI;
import org.b3log.solo.cache.*;
import org.b3log.solo.repository.*; import org.b3log.solo.repository.*;
import org.b3log.solo.repository.impl.*; import org.b3log.solo.repository.impl.*;
import org.b3log.solo.service.*; import org.b3log.solo.service.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import java.sql.Connection; import java.sql.Connection;
...@@ -37,8 +39,7 @@ import java.util.Locale; ...@@ -37,8 +39,7 @@ import java.util.Locale;
* Abstract test case. * Abstract test case.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.3.0.10, Sep 6, 2017 * @version 2.3.0.11, Sep 25, 2018
* @see #beforeClass()
*/ */
public abstract class AbstractTestCase { public abstract class AbstractTestCase {
...@@ -78,8 +79,20 @@ public abstract class AbstractTestCase { ...@@ -78,8 +79,20 @@ public abstract class AbstractTestCase {
* <li>Clears all caches</li> * <li>Clears all caches</li>
* </ul> * </ul>
*/ */
@BeforeClass @AfterClass
public void afterClass() { public void afterClass() {
final ArticleCache articleCache = beanManager.getReference(ArticleCache.class);
articleCache.clear();
final CommentCache commentCache = beanManager.getReference(CommentCache.class);
commentCache.clear();
final OptionCache optionCache = beanManager.getReference(OptionCache.class);
optionCache.clear();
final PageCache pageCache = beanManager.getReference(PageCache.class);
pageCache.clear();
final StatisticCache statisticCache = beanManager.getReference(StatisticCache.class);
statisticCache.clear();
final UserCache userCache = beanManager.getReference(UserCache.class);
userCache.clear();
} }
/** /**
......
...@@ -18,15 +18,18 @@ ...@@ -18,15 +18,18 @@
package org.b3log.solo.util; package org.b3log.solo.util;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.b3log.latke.Latkes;
import org.b3log.latke.util.Stopwatchs; import org.b3log.latke.util.Stopwatchs;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.List; import java.util.List;
import java.util.Locale;
/** /**
* {@link org.b3log.solo.util.Markdowns} test case. * {@link org.b3log.solo.util.Markdowns} test case.
...@@ -37,6 +40,12 @@ import java.util.List; ...@@ -37,6 +40,12 @@ import java.util.List;
*/ */
public final class MarkdownsTestCase { public final class MarkdownsTestCase {
@BeforeClass
public void beforeClass() {
Latkes.initRuntimeEnv();
Latkes.setLocale(Locale.SIMPLIFIED_CHINESE);
}
/** /**
* Test method for {@linkplain Markdowns#toHTML(java.lang.String)}. * Test method for {@linkplain Markdowns#toHTML(java.lang.String)}.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment