Skip to content

Commit

Permalink
Test Cases 3.0.0
Browse files Browse the repository at this point in the history
- Fixes
- Lodging doc
  • Loading branch information
autumoswitzerland committed Jul 5, 2024
1 parent 10d8670 commit 79f69fe
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 35 deletions.
2 changes: 1 addition & 1 deletion cfg/beetroot.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ ws_cache_size=2
# File cache size in kB.
# Upper limit to cache a file.
#
ws_file_cache_size=100
ws_file_cache_size=200

#
# Response buffer size in kBytes.
Expand Down
2 changes: 1 addition & 1 deletion cfg/beetroot_dist.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ ws_cache_size=2
# File cache size in kB.
# Upper limit to cache a file.
#
ws_file_cache_size=100
ws_file_cache_size=200

#
# Response buffer size in kBytes.
Expand Down
7 changes: 4 additions & 3 deletions cfg/beetroot_test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,13 @@ ws_use_csrf_tokens=yes
#
# Overall max. cache size in MB.
#
ws_cache_size=2
ws_cache_size=1

#
# File cache size in kB.
# Upper limit to cache a file.
#
ws_file_cache_size=100
ws_file_cache_size=200

#
# Response buffer size in kBytes.
Expand Down Expand Up @@ -748,6 +748,7 @@ ws_mime_allowed_octet = image/png \
#
ws_mime_allowed_archive = application/zip \
application/gzip \
application/x-tar
application/x-tar \
application/java-archive


4 changes: 3 additions & 1 deletion cfg/logging-dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

</RollingFile>

<!-- Used to show server log on the web -->
<!-- Used to show server log on the web, remove if not needed -->
<LogEventAppender name="logEventAppender" />

</Appenders>
Expand All @@ -47,11 +47,13 @@

<Logger name="ch.autumo.beetroot" level="info" additivity="false">
<AppenderRef ref="console" />
<!-- Used to show server log on the web, remove if not needed -->
<AppenderRef ref="logEventAppender" />
</Logger>

<Root level="info" additivity="false">
<AppenderRef ref="console" />
<!-- Used to show server log on the web, remove if not needed -->
<AppenderRef ref="logEventAppender" />
</Root>

Expand Down
6 changes: 4 additions & 2 deletions cfg/logging.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Version: 3.0 - 2023 autumo GmbH
-->

<Configuration status="error" name="BeetRootConfig" strict="true">
<Configuration status="error" name="BeetRootConfig">

<Properties>
<Property name="basePath">${sys:ROOTPATH}/log</Property>
Expand Down Expand Up @@ -39,7 +39,7 @@

</RollingFile>

<!-- Used to show server log on the web -->
<!-- Used to show server log on the web, remove if not needed -->
<LogEventAppender name="logEventAppender" />

</Appenders>
Expand All @@ -48,11 +48,13 @@

<Logger name="ch.autumo.beetroot" level="info" additivity="false">
<AppenderRef ref="console" />
<!-- Used to show server log on the web, remove if not needed -->
<AppenderRef ref="logEventAppender" />
</Logger>

<Root level="info" additivity="false">
<AppenderRef ref="console" />
<!-- Used to show server log on the web, remove if not needed -->
<AppenderRef ref="logEventAppender" />
</Root>

Expand Down
1 change: 1 addition & 0 deletions cfg/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
</Package>

<!-- System -->
<!-- Used to show server log on the web, remove if not needed -->
<Package name="ch.autumo.beetroot.handler.system">
<Route path="/:lang/system/log" handler="LogHandler" name="log" />
</Package>
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/ch/autumo/beetroot/cache/FileCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public FileCache(Path filePath, ContentType contentType) throws IOException {
*
* @param filePath file path
* @param mimeType mime type, e.g. "text/html"
* @param forcedCaching force caching?
* @param forcedCaching force caching? Force caching breaks the file size limit, but not the cache size limit!
* @throws IOException IO exception
*/
public FileCache(Path filePath, String mimeType, boolean forcedCaching) throws IOException {
Expand All @@ -154,7 +154,7 @@ public FileCache(Path filePath, String mimeType, boolean forcedCaching) throws I
* @param filePath file path
* @param contentType content header type, e.g.
* "text/html; charset=UTF-8"
* @param forcedCaching force caching?
* @param forcedCaching force caching? Force caching breaks the file size limit, but not the cache size limit!
* @throws IOException IO exception
*/
public FileCache(Path filePath, ContentType contentType, boolean forcedCaching) throws IOException {
Expand Down Expand Up @@ -196,29 +196,30 @@ public FileCache(Path filePath, ContentType contentType, boolean forcedCaching)

/**
* File cache constructor.
* Resources are immutable, hence no re-caching will be done.
*
* @param resourcePath resource path
* @throws IOException IO exception
*/
public FileCache(String resourcePath) throws IOException {

this(resourcePath, (String) null);
}

/**
* File cache constructor.
* Resources are immutable, hence no re-caching will be done.
*
* @param resourcePath resource path
* @param mimeType mime type, e.g. "text/html"
* @throws IOException IO exception
*/
public FileCache(String resourcePath, String mimeType) throws IOException {

this(resourcePath, getContentType(mimeType));
}

/**
* File cache constructor.
* Resources are immutable, hence no re-caching will be done.
*
* @param resourcePath resource path
* @param contentType content header type, e.g.
Expand Down Expand Up @@ -448,6 +449,14 @@ public long getLastModified() {
return lastModified;
}

/**
* Get file size.
* @return file size
*/
public long getFileSize() {
return fileSize;
}

/**
* Is it an archive?
* @return is it an archive
Expand All @@ -458,6 +467,7 @@ public boolean isArchive() {

/**
* Is it a binary?
* Resources are immutable, hence no re-caching will be done.
* @return is it a binary
*/
public boolean isBinary() {
Expand Down
40 changes: 17 additions & 23 deletions src/main/java/ch/autumo/beetroot/cache/FileCacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public class FileCacheManager {
private Map<String, FileCache> cacheMap = new ConcurrentHashMap<String, FileCache>();

private long size = 0;
private boolean maxSizeReached = false;


/**
Expand All @@ -82,19 +81,11 @@ public long getSize() {
return size;
}

/**
* Is max. cache size reached?
* @return true, if so
*/
public boolean isMaxSizeReached() {
return maxSizeReached;
}

/**
* Is there space left in the cache?
*
* @param oldValueInBytes old amount of bytes that have been used
* for the sam resource
* for the same resource
* @param newValueInBytes new amount of bytes that is used by the
* changed resource
* @return true, is there is space, otherwise false
Expand All @@ -115,22 +106,15 @@ public synchronized boolean hasSpace(long oldValueInBytes, long newValueInBytes)
* Update cache size.
*
* @param oldValueInBytes old amount of bytes that have been used
* for the sam resource
* for the same resource
* @param newValueInBytes new amount of bytes that is used by the
* changed resource
* @return true if max. cache size has been reached, otherwise false
* @return new cache size;
*/
public synchronized boolean updateCacheSize(long oldValueInBytes, long newValueInBytes) {

public synchronized long updateCacheSize(long oldValueInBytes, long newValueInBytes) {
size -= oldValueInBytes;
size += newValueInBytes;

if (size > MAX_CACHE_SIZE)
maxSizeReached = true;
else
maxSizeReached = false;

return maxSizeReached;
return size;
}

/**
Expand Down Expand Up @@ -182,7 +166,8 @@ public FileCache findOrCreate(String path) throws IOException {
* Find or create file cache.
*
* @param path file path
* @param forceCaching caching is forced when true if max. cache size isn't reached
* @param forcedCaching caching is forced when true if max. cache size isn't reached;
* force caching breaks the file size limit, but not the cache size limit!
* @return file cache
* @throws IOException IO exception
*/
Expand Down Expand Up @@ -219,7 +204,8 @@ public FileCache findOrCreate(Path path) throws IOException {
* Find or create file cache.
*
* @param path resource path
* @param forcedCaching caching is forced when true if max. cache size isn't reached.
* @param forcedCaching caching is forced when true if max. cache size isn't reached;
* force caching breaks the file size limit, but not the cache size limit!
* @return file cache
* @throws IOException IO exception
*/
Expand Down Expand Up @@ -294,9 +280,17 @@ public void clear() {
final FileCache fCache = cacheMap.get(key);
fCache.clear();
}
this.size = 0;
cacheMap.clear();
}

/**
* Get maximum size of this cache.
* @return max. size
*/
public long getMaxSize() {
return MAX_CACHE_SIZE;
}

/**
* Get normalized path.
Expand Down
Empty file added src/main/resources/empty
Empty file.
21 changes: 21 additions & 0 deletions src/test/java/ch/autumo/beetroot/DBManagerTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
*
* Copyright (c) 2024 autumo Ltd. Switzerland, Michael Gasche
*
* Licensed 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.
*
*/
package ch.autumo.beetroot;

import java.util.Iterator;
Expand All @@ -8,6 +25,10 @@

import ch.autumo.beetroot.utils.DBField;


/**
* DB manager test. See also {@link ModelTest}.
*/
public class DBManagerTest {

@BeforeClass
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/ch/autumo/beetroot/ModelTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
*
* Copyright (c) 2024 autumo Ltd. Switzerland, Michael Gasche
*
* Licensed 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.
*
*/
package ch.autumo.beetroot;

import static org.junit.Assert.assertEquals;
Expand All @@ -13,6 +30,7 @@
import ch.autumo.beetroot.models.Product;
import ch.autumo.beetroot.models.Variant;


/**
* Model test.
*
Expand Down
Loading

0 comments on commit 79f69fe

Please sign in to comment.