How to set up web caching settings with GAE using Java? - google-app-engine

I've been trying to figure out where I can set my cache settings for my website I'm hosting on GAE but I can't find the info on their documentation, nor does Google yield any results. I've read a lot about caching but all the results I find or code examples are using Apache.
Any documentation links? Or just general info of where I actually write the cache settings? Somewhere in appengine-web.xml perhaps?
Thanks. Any info/docs at all would be appreciated.
edit: I have tried something like this in appengine-web.xml but it doesn't seem to be actually caching anything when I test with Chrome Dev Tools —
<static-files>
<include path="/**.png" expiration="7d" />
<include path="/**.jpg" expiration="7d" />
<include path="/**.ico" expiration="7d" />
<include path="/**.js" expiration="7d" />
<include path="/**.svg" expiration="7d" />
<include path="/**.ttf" expiration="7d" />
<include path="/**.woff" expiration="7d" />
<include path="/**.css" />
</static-files>
Also as soon as I add a single static file like this:
<static-files>
<include path="/img/top_img.jpg" expiration="4d 5h" />
</static-files>
I get a ton of errors saying that I need to include everything in my static-files list, like this — WARNING: Can not serve /paypal_button.svg directly. You need to include it in <static-files> in your appengine-web.xml.
edit: here is curl -v log —
< HTTP/1.1 200 OK
< Content-Length: 61009
< Content-Type: text/html
< Last-Modified: Wed, 13 Jan 2016 06:19:21 GMT
< Cache-Control: public, max-age=600
< Server: Development/1.0
< Date: Wed, 13 Jan 2016 07:33:39 GMT
So caching is enabled.. but I cannot figure how how to change expiration dates of individual static files using GAE.
edit: when I test on prod server with this code:
<static-files>
<include path="/**.png" expiration="999d" />
</static-files>
None of my resources load, I get these errors:
Failed to load resource: the server responded with a status of 404 (Not Found)
on everything that isn't a .png

Alright, after a lot of annoyance I was able to get it to work properly. Basically with appengine-web.xml as soon as you list one thing as a <static-file> you have to list every filetype that you have or else it will not know if it's static or not. So I was able to do this—
<static-files>
<include path="/**.png" expiration="365d" />
<include path="/**.svg" expiration="365d" />
<include path="/**.jpg" expiration="365d" />
<include path="/**.zip" expiration="365d" />
<include path="/**.pdf" expiration="365d" />
<include path="/**.hex" expiration="365d" />
<include path="/**.js" expiration="365d" />
<include path="/**.js.map" expiration="365d" />
<include path="/**.ttf" expiration="365d" />
<include path="/**.gif" expiration="365d" />
<include path="/**.woff" expiration="365d" />
<include path="/**.css" expiration="365d" />
<include path="/**.html" expiration="1d"/>
</static-files>
and now all the http-headers look correct. Just be sure to include every filetype/file you have on your website or else it will not load that resource.
Cheers.

Related

How to execute 2 test classes in order using TestNG if classes belongs to different tests?

I'm new to Automation and wondering how do I execute 2 test classes in a specific order if they belong to different tests.
I have the following testng.xml file:
<suite name="myTestProject" parallel="false">
<listeners>
<listener class-name="utility.eTestListener"></listener>
</listeners>
<test name="LOGINTEST">
<parameter name="browserName" value="chrome"/>
<parameter name="url" value="https://url/"/>
<groups>
<define name = "all">
<exclude name="negativeTest"/>
<include name="loginTest"/>
</define>
<run>
<include name = "all"/>
</run>
</groups>
<classes>
<class name="site.tests.suite.TestClass1"/>
</classes>
</test>
<test name="FILE_RECON">
<groups>
<define name = "all">
<include name="IncomingVisa"/>
</define>
<run>
<include name="All"/>
</run>
</groups>
<classes>
<class name="site.tests.suite.TestClass2"/>
</classes>
</test>
</suite>
When executing the project, TestClass2 is executed first.
How can I change the testng.xml or perform some other changes in order for the TestClass1 run first and TestClass2 run second?
Within TestNG <test> is the smallest unit of execution. You cannot span across <test> tags and visualize an execution.
So this is currently NOT supported in TestNG and I am pretty sure that its not likely to be supported as well.
If you would like to control the order of the test classes, then you would need to include them within the same <test> tag only.

Selenium TestNG reporting for multiple tests in a suite

I want to run same set of test cases in multiple browsers. For this, I have put tests(each test is for individual browser) under a suite in testng xml. After running, I get single html report from testng, If there is a test failure in one of the browser, it is not visible in report. Is there other way to handle it?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Smoke Test" verbose="2" preserve-order="true">
<parameter name="baseUrl" value="https:test.com"/>
<test name="Smoke_Firefox">
<parameter name="browser" value="firefox"/>
<classes>
<class name="test.TestLogin">
<methods>
<include name="test_login"/>
<include name="test_logout"/>
</methods>
</class>
</classes>
</test>
<test name="Smoke_Chrome">
<parameter name="browser" value="chrome"/>
<classes>
<class name="test.TestLogin">
<methods>
<include name="test_login"/>
<include name="test_logout"/>
</methods>
</class>
</classes>
</test>
<test name="Smoke_IE">
<parameter name="browser" value="ie"/>
<classes>
<class name="test.TestLogin">
<methods>
<include name="test_login"/>
<include name="test_logout"/>
</methods>
</class>
</classes>
</test>
</suite>
I got my answer. It had to update testng configuration in Intellijidea to get the report.

WPF: what could happen if 2 instances of my application report to the same log [duplicate]

I'm using a RollingFileAppender to log some info to a file with a conversionPattern (in the web.config) that looks like this for the header of each log section:
<conversionPattern value="%date - %property{userId} - %property{method}%newline--------------------------------%newline%message%newline%newline"/>
I'd like to log details under this header as bullet points. I'm currently trying to use another RollingFileAppender that logs to the same file with a simple conversionPattern of just a dash, like this:
<conversionPattern value="- %message%newline"/>
But these messages aren't making it into the log file. I'm using Log.Info() for the header and Log.Debug() for the bullet points and filtering each appender on their respective log levels. Is what I'm trying to do possible? Or is there a better way to get header and detail information into a log file from log4net?
Yes you can have two log4net appenders that append (write) to the same log file.
You need to place the following line in each of your Appenders:
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
This will make log4net use a minimal locking model that allows multiple processes to write to the same file.
Here's an example XML that uses two appenders writing to the same log file:
<log4net debug="false">
<appender name="RollingLogFileAppender1" type="log4net.Appender.RollingFileAppender">
<!-- this configures a log for the application messages -->
<file value="TestLog.log" />
<appendToFile value="true" />
<!-- next line uses a minimal locking model that allows multiple processes to write to the same file -->
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<!-- make the most recent log the highest numbered log -->
<countDirection value="1" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5level %date{MM-dd-yyyy HH:mm:ss.ff} [%property{NDC}] %message%newline [Thread: %thread] %c{1} Method:%method(%file{1}, Line:%line) %newline" />
</layout>
<!-- The following two filters insure only log requests of
version '1' use this Appender -->
</appender>
<appender name="RollingLogFileAppender2" type="log4net.Appender.RollingFileAppender">
<file value="TestLog.log" />
<appendToFile value="true" />
<!-- next line uses a minimal locking model that allows multiple processes to write to the same file -->
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<!-- make the most recent log the highest numbered log -->
<countDirection value="1" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5level %date{MM-dd-yyyy HH:mm:ss.ff} [%property{NDC}] [Thread: %thread] %c{1} Method:%method(%file{1}, Line:%line) %newline%message" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender1" />
<appender-ref ref="RollingLogFileAppender2" />
</root>
This can be found in the Apache documentation here:
Apache Log4Net Docs
Just search on this page for 'same file'.
Hope this helps.
You could realize if there is any problem with log4net checking the output window on visual studio. The library log errors there, very useful to detect configuration mistakes.

log4net log file not being written when the app is deployed

I have a WPF app that uses log4net. When I run it in Visual Studio, the log file is created in the Debug or Release folder as expected.
However, when I create an installer and run the installed app, the log file is not created. I added the following lines to the code...
string logFilePath = ((Hierarchy)LogManager.GetRepository())
.Root.Appenders.OfType<FileAppender>()
.FirstOrDefault()?.File;
using (StreamWriter sw = new StreamWriter(#"d:\log.log")) {
sw.WriteLine("Log file: " + logFilePath);
}
...to enable me to check that the log file was being written in the location I expected. It showed me that the log file was supposed to be written to C:\Program Files (x86)\Physio Diary\PhysioDiaryClient.log which is what I expected.
However, the file doesn't exist. Any idea why?
Here is the top of the App.config file...
<?xml version="1.0"
encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" />
</configSections>
<log4net>
<appender name="RollingFileAppender"
type="log4net.Appender.RollingFileAppender">
<param name="File"
value="PhysioDiaryClient.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="2" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-7level %logger - %message%newline%exception" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>
The bottom of the file looks like this...
<startup>
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
The bits in between are all to do with the WCF services that the app uses.
Anyone any ideas?
Edit: As a test, I tried hard-coding the log file path in App.config to my D: drive (so it's hard-coded, and no question of a permissions issue), but the file still wasn't created.
Thanks to #dymanoid for pointing me in the right direction. The log4net docs are a bit weak in this area, but I found this answer that pointed out that you can use normal environment variables in the config file.
With the aid of this list of environment variables, I ended up with the following...
<param name="File"
value="${LOCALAPPDATA}\Physio Diary\PhysioDiaryClient.log" />
This correctly write the file to C:\Users\MyUsername\AppData\Local\Physio Diary\PhysioDiaryClient.log
Hope this helps someone.

Google app engine 100 URLMap entries limitation

I have been using google app engine to build my website, and met a problem about the maximum number of URLMap (I had 101 URLs, but the limit is 100). Here is the error message:
Fatal error when loading application configuration:
Invalid object:
Found more than 100 URLMap entries in application configuration
in "\AppPest\app.yaml", line 269, column 28
I tried to change the setting MAX_URL_MAPS = 1000 in the file appinfo.py, but it did not work. Can anyone give me some suggestions?
EDIT:
Another question is that some of my URLs are similar, like a_input.html, b_input.html, c_input.html. Is there a way to simplify it in order to reduce the number of URLs? Here is an example of my yaml file
#a
- url: /a_input.html
script: a/a_input.py
#b
- url: /b_input.html
script: b/b_input.py
#c
- url: /c_input.html
script: c/c_input.py
The solution will depend on the language you are using. If you are using python 2.7, what you can do is to:
1) Use regular expression for defining the urls, see this doc for more details
handlers:
- url: /(.*?)_input.html
script: /input/\1.app
2) Point a group of urls to the same app and let the app handle the different requests.
handlers:
- url: /(.*?)_input.html
script: /input/input.app
app = webapp2.WSGIApplication([('/a_input.html', AInputPage), ('/b_input.html', BInputPage)])
From the information you provided I cant tell if a_input.html, b_html are static or not. But if they are static yo could also do:
3) Refer them with the static file handlers, which also accept regular expressions.
- url: /input
static_dir: static/input
See issue 1444 for some more details, specially for java related ones.
I had the same problem using Java SDK.
I revolved removing index.html from welcome-file-list.
Now my entrypoint is index.jsp with a redirect to my index.html page.
In web.xml:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
In appengine-web.xml:
<static-files>
<include path="/fonts/**" />
<include path="/app/fonts/**" />
<include path="/**.html" />
<include path="/**.js" />
<include path="/**.css" />
<include path="/**.ico" />
<include path="/**.png" />
<include path="/**.jpg" />
<include path="/**.jpeg" />
<include path="/**.gif" />
</static-files>

Resources