Skip to content

OWLS-81928 - JUnit5: Convert ItManagedCoherence (testCreateCoherenceDomainInImageUsingWdt) test #1822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import java.util.List;

import oracle.weblogic.kubernetes.actions.impl.primitive.Command;
import oracle.weblogic.kubernetes.utils.FileUtils;

import static oracle.weblogic.kubernetes.actions.ActionConstants.APP_DIR;
import static oracle.weblogic.kubernetes.actions.ActionConstants.ARCHIVE_DIR;
import static oracle.weblogic.kubernetes.actions.ActionConstants.WORK_DIR;
import static oracle.weblogic.kubernetes.actions.impl.primitive.Command.defaultCommandParams;
import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory;
import static oracle.weblogic.kubernetes.utils.FileUtils.cleanupDirectory;
Expand Down Expand Up @@ -117,8 +119,25 @@ public boolean buildCoherence() {
}

// build the app archive
String jarPath = String.format("%s.gar", params.appName());
boolean jarBuilt = buildJarArchive(jarPath, ARCHIVE_SRC_DIR);
boolean jarBuilt = false;
if (params.appName().contains("coherence-proxy")) {
String jarPath = String.format("%s.gar", params.appName());
jarBuilt = buildJarArchive(jarPath, ARCHIVE_SRC_DIR);
} else if (params.appName().contains("CoherenceApp")) {
String [] appTypes = {"ear", "gar"};
try {
for (String appType : appTypes) {
String appSrcDir = String.format("%s/%s/u01/application/builddir/%s.%s",
WORK_DIR, params.appName(), params.appName(), appType);
String archiveSrcDir = String.format("%s/%s.%s", ARCHIVE_SRC_DIR, params.appName(), appType);
FileUtils.copy(Paths.get(appSrcDir), Paths.get(archiveSrcDir));
}
jarBuilt = true;
} catch (IOException ex) {
getLogger().severe("Failed to copy Coherence app ", ex.getMessage());
return false;
}
}

// build a zip file that can be passed to WIT
String zipPath = String.format("%s/%s.zip", ARCHIVE_DIR, params.appName());
Expand Down Expand Up @@ -195,11 +214,19 @@ public boolean buildCoherenceZipArchive(String zipPath, String srcDir) {
zipPath,
params.appName());

if (params.appName().contains("CoherenceApp")) {
cmd = String.format(
"cd %s ; zip -r %s.zip wlsdeploy/applications ",
ARCHIVE_DIR,
params.appName()
);
}

return Command.withParams(
defaultCommandParams()
.command(cmd)
.redirect(false))
.execute();
defaultCommandParams()
.command(cmd)
.redirect(false))
.execute();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ public static String createImageAndVerify(String imageNameBase,
if (appSrcDirList != null && appSrcDirList.size() != 0 && appSrcDirList.get(0) != null) {
List<String> archiveAppsList = new ArrayList<>();
List<String> buildAppDirList = new ArrayList<>(appSrcDirList);
boolean buildCoherenceGar = false;
boolean buildCoherence = false;

for (String appSrcDir : appSrcDirList) {
if (appSrcDir.contains(".war") || appSrcDir.contains(".ear")) {
Expand All @@ -970,8 +970,8 @@ public static String createImageAndVerify(String imageNameBase,
archiveAppsList.add(appSrcDir);
}

if (appSrcDir.contains("coherence")) {
buildCoherenceGar = true;
if (appSrcDir.contains("coherence-proxy") || appSrcDir.contains("CoherenceApp")) {
buildCoherence = true;
}
}

Expand All @@ -998,7 +998,7 @@ public static String createImageAndVerify(String imageNameBase,
zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, buildAppDirList.get(0));
// build the archive list
archiveList.add(zipFile);
} else if (buildCoherenceGar) {
} else if (buildCoherence) {
// build the Coherence GAR file
assertTrue(buildCoherenceArchive(defaultAppParams()
.srcDirList(buildAppDirList)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,14 @@ public static void makeDirectories(String namespace,
});
}

private static void copy(Path source, Path dest) throws IOException {
/**
* Copy file from source directory to destination directory.
*
* @param source path of source file
* @param dest path of target file
* @throws IOException if the operation encounters an issue
*/
public static void copy(Path source, Path dest) throws IOException {
getLogger().finest("Copying {0} to {1} source.fileName = {2}", source, dest, source.getFileName());
if (!dest.toFile().isDirectory()) {
Files.copy(source, dest, REPLACE_EXISTING);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!--
Copyright (c) 2020, Oracle Corporation and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
-->
<project name="coherence.app" default="build">
<description>
coherence-cache-config file is under
APP-INF/classes/META-INF; coherence.jar and active-cache.jar are
deployed as shared libraries
</description>

<dirname file="${ant.file.coherence.app}"
property="coherence.app.dir" />

<property name="tempdir" location="tempdir" />
<property name="builddir" location="builddir" />

<path id="build.classpath">
<pathelement path="${env.ORACLE_HOME}/wlserver/server/lib/weblogic.jar"/>
<pathelement path="${env.ORACLE_HOME}/coherence/lib/coherence.jar"/>
</path>

<!-- Following application needs to be built one after the another -->
<target name="build">
<delete dir="${tempdir}" quiet="true" />
<mkdir dir="${tempdir}" />
<antcall target="build-gar">
<param name="app.dir" value="${coherence.app.dir}/gar" />
<param name="app" value="CoherenceApp" />
<param name="resource.dir"
value="${coherence.app.dir}/gar/META-INF" />
</antcall>
<antcall target="build-war">
<param name="app.dir" value="${coherence.app.dir}/ear" />
<param name="app" value="CoherenceApp" />
<param name="resource.dir" value="${coherence.app.dir}/ear/WEB-INF" />
</antcall>
<antcall target="build-ear">
<param name="app.dir" value="${coherence.app.dir}/ear" />
<param name="app" value="CoherenceApp" />
<param name="resource.dir" value="${coherence.app.dir}/ear/WEB-INF" />
</antcall>
<delete dir="${tempdir}" quiet="true" />
</target>

<target name="build-gar">
<mkdir dir="${tempdir}/gar" />
<mkdir dir="${tempdir}/gar/META-INF" />
<echo message="${test.src.dir}" />
<echo message="building ${app}" />
<javac debug="${javac.debug}" srcdir="."
includes="gar/pof/**.java,gar/contacts/**.java"
destdir="${tempdir}/gar">
<classpath>
<path refid="build.classpath" />
</classpath>
</javac>

<copy file="${resource.dir}/coherence-application.xml" tofile="${tempdir}/gar/META-INF/coherence-application.xml" />
<copy file="${resource.dir}/cache-config.xml" tofile="${tempdir}/gar/META-INF/cache-config.xml" />
<copy file="${resource.dir}/pof-config.xml" tofile="${tempdir}/gar/META-INF/pof-config.xml" />
<jar jarfile="${builddir}/${app}.gar" basedir="${tempdir}/gar" />
</target>

<target name="build-war">
<mkdir dir="${tempdir}/war/WEB-INF" />
<mkdir dir="${tempdir}/war/WEB-INF/classes" />
<echo message="building ${app}" />
<javac debug="${javac.debug}" srcdir="."
includes="ear/**.java"
destdir="${tempdir}/war/WEB-INF/classes">
<classpath>
<path refid="build.classpath" />
<pathelement path="${tempdir}/gar" />
</classpath>
</javac>
<jar jarfile="${builddir}/${app}.war" basedir="${tempdir}/war" />
</target>

<target name="build-ear">
<mkdir dir="${tempdir}/ear" />
<mkdir dir="${tempdir}/ear/META-INF" />
<copy file="${app.dir}/META-INF/application.xml"
tofile="${tempdir}/ear/META-INF/application.xml" />
<copy
file="${app.dir}/META-INF/weblogic-application.xml"
tofile="${tempdir}/ear/META-INF/weblogic-application.xml" />
<copy todir="${tempdir}/ear/">
<fileset dir="${builddir}" includes="${app}.war" />
<fileset dir="${builddir}" includes="${app}.gar" />
</copy>
<echo message="building ${app}" />
<jar jarfile="${builddir}/${app}.ear" basedir="${tempdir}/ear" />
</target>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Copyright (c) 2020, Oracle Corporation and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package com.examples.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.examples.pof.Contact;
import com.examples.pof.ContactId;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;

/**
* This web application is used for following with respect to Coherence cache depending on user
* action. 1. Populating the cahce using "add" , first name and second name used for populating the
* data. 2. To get the cache size using "count" 3. Clear the cache using "clear" 4. Get all cached
* data details using "get"
*/
@WebServlet(
name = "CoherenceApp",
urlPatterns = {"/CoherenceApp"})
public class CoherenceApp extends HttpServlet {

private ArrayList keyList = new ArrayList<ContactId>();

public CoherenceApp() {
super();
}

/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();

String action = request.getParameter("action");
String firstName = request.getParameter("first");
String secondName = request.getParameter("second");

// Call respective methods based on user action
if (action.equals("add")) {
add(request, response);
} else if (action.equals("size")) {
count(request, response);
} else if (action.endsWith("clear")) {
clear(request, response);
} else if (action.endsWith("get")) {
get(request, response);
}
}

/*
* Clea the cache and updates the size after cache
*/
private void clear(HttpServletRequest request, HttpServletResponse response) throws IOException {
NamedCache cache = CacheFactory.getCache("contacts");
cache.clear();
PrintWriter out = response.getWriter();
if (cache.size() == 0) {
out.println("Cache is cleared and current size is :" + cache.size());
} else {
out.println("Cache is not cleared and current size is :" + cache.size());
}
}

/*
* Returns the current cache size
*/
private void count(HttpServletRequest request, HttpServletResponse response) throws IOException {
NamedCache cache = CacheFactory.getCache("contacts");
PrintWriter out = response.getWriter();
out.println(cache.size());
}

/*
* Add first name and second name as cache data
*/
private void add(HttpServletRequest request, HttpServletResponse response) throws IOException {
NamedCache cache = CacheFactory.getCache("contacts");
String firstName = request.getParameter("first");
String secondName = request.getParameter("second");
PrintWriter out = response.getWriter();
Contact contact = new Contact(firstName, secondName);

ContactId contactID = new ContactId(firstName, secondName);
keyList.add(contactID);
cache.put(contactID, contact);
Contact contactGet = (Contact) cache.get(contactID);
out.println("\nContact added:" + contactGet);
}

/*
* Retrieve all cached data as of now
*/
private void get(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
NamedCache cacheMap = CacheFactory.getCache("contacts");
Set keys = cacheMap.keySet();
PrintWriter out = response.getWriter();
Iterator iterate = keys.iterator();
while (iterate.hasNext()) {
ContactId key = (ContactId) iterate.next();
Contact contactGet = (Contact) cacheMap.get(key);
out.println(contactGet);
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on
// the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
} // </editor-fold>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2020, Oracle Corporation and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
-->
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
version="5">

<display-name>Coherence Test App</display-name>
<module>
<web>
<web-uri>CoherenceApp.war</web-uri>
<context-root>CoherenceApp</context-root>
</web>
</module>
</application>
Loading