Skip to content
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

Bill Bai's Homework 5&6 @Bagdan #49

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
049d201
Implement getAccidentByIndex7 and getAccidentsByLocation7
bill8white Apr 7, 2016
8beb023
All Java 7 function implemented
bill8white Apr 12, 2016
142734f
All Java 8 Stream function implemented
bill8white Apr 13, 2016
bca239b
Use Ordering to sort map with values
bill8white Apr 13, 2016
ad73b0a
Refactor code
bill8white Apr 14, 2016
1fc41f7
Memory session homework
bill8white Apr 19, 2016
0f9caa2
Merge branch 'master' of github.com:bagedan/EPAM-JMP
bill8white Apr 26, 2016
9672c35
New class for home work 3
bill8white May 1, 2016
54fe97c
Read/Proc task word
bill8white May 1, 2016
169677d
Sync stop producer and consumer task
bill8white May 2, 2016
b9c3ace
All Thread work
bill8white May 2, 2016
256cf96
Code cleanup
bill8white May 2, 2016
1dc34c0
Add some test suite
bill8white May 3, 2016
b6fb684
Home work 4
bill8white May 4, 2016
3b0ca0a
spring boot sample implement and tested
bill8white May 22, 2016
eee6ac3
Test framework setup
bill8white May 22, 2016
fd6a0b5
restapi with findOne implement
bill8white May 22, 2016
9328204
Temp check in
bill8white May 24, 2016
2ad31a7
Correct pom.xml, add dbunit function
bill8white May 25, 2016
d858af3
Temp check in for sync
bill8white May 25, 2016
52b2df2
check in some modify from laptop
bill8white May 26, 2016
3552861
Merge with desktop
bill8white May 26, 2016
c5f4238
Narrow down issue
bill8white May 26, 2016
0d1c572
Clean pom.xml to fix dependence conflict issue on spring boot
bill8white May 26, 2016
b889085
Clean pom.xml to fix dependence conflict issue on spring boot
bill8white May 26, 2016
2e048b0
RoadCondition Entity implement and unit tested with sample dataset
bill8white May 27, 2016
016aacf
Simple Accidents Entity restore and tested
bill8white May 27, 2016
65beff0
RestApplication work with POST/PUT/DEL"
bill8white May 27, 2016
b599404
Add test sample data
bill8white May 27, 2016
42ebb8d
@OntToOne, countBy implement and test
bill8white May 28, 2016
1e50fc7
Implement Accident DB Service for customer query
bill8white May 28, 2016
7b1fb12
Count by Weather and Year Mock function implement
bill8white May 28, 2016
6280ca6
Weather condition entity and related query
bill8white May 28, 2016
68e7fff
Homework 5 finish
bill8white May 28, 2016
091b497
WeatherController basic function unit test passed
bill8white May 29, 2016
7c8db8d
REST post with Weather done
bill8white May 29, 2016
7ca864c
Rest PUT command implement/test
bill8white Jun 5, 2016
11ed40e
Exception Handle for Weather Controller
bill8white Jun 5, 2016
2fc85be
HomeWork6Test finish
bill8white Jun 9, 2016
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
16 changes: 16 additions & 0 deletions homework/bill_gc.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Java HotSpot(TM) 64-Bit Server VM (25.20-b23) for windows-amd64 JRE (1.8.0_20-b26), built on Jul 30 2014 13:51:23 by "java_re" with MS VC++ 10.0 (VS2010)
Memory: 4k page, physical 8271460k(3665084k free), swap 10237540k(4273076k free)
CommandLine flags: -XX:InitialHeapSize=132343360 -XX:MaxHeapSize=2117493760 -XX:+PrintGC -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
3.961: [GC (Allocation Failure) 23808K->21424K(125952K), 0.0080784 secs]
4.551: [GC (Allocation Failure) 53438K->52064K(125952K), 0.0110631 secs]
5.875: [GC (Allocation Failure) 83678K->82752K(125952K), 0.0129618 secs]
5.888: [Full GC (Ergonomics) 82752K->82716K(201216K), 0.0267797 secs]
6.612: [GC (Allocation Failure) 114034K->123740K(221184K), 0.0133295 secs]
6.625: [Full GC (Ergonomics) 123740K->113436K(273920K), 0.0038620 secs]
8.864: [GC (Allocation Failure) 165577K->205660K(282624K), 0.0266288 secs]
8.890: [Full GC (Ergonomics) 205660K->164636K(384512K), 0.0206266 secs]
10.402: [GC (Allocation Failure) 216917K->215868K(418304K), 0.0119434 secs]
14.423: [GC (Allocation Failure) 309699K->308060K(418304K), 0.0319572 secs]
14.455: [Full GC (Ergonomics) 308060K->307997K(593920K), 0.0288107 secs]
16.737: [GC (Allocation Failure) 401938K->410461K(655872K), 0.0324336 secs]
16.770: [Full GC (Ergonomics) 410461K->400157K(776192K), 0.0112225 secs]
53 changes: 53 additions & 0 deletions homework/bill_jvm32_gc.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Java HotSpot(TM) Client VM (25.51-b03) for windows-x86 JRE (1.8.0_51-b16), built on Jun 8 2015 18:00:23 by "java_re" with MS VC++ 10.0 (VS2010)
Memory: 4k page, physical 8271460k(4177156k free), swap 10237540k(4761452k free)
CommandLine flags: -XX:ErrorFile=C:\Users\Bill\java_error_in_IDEA_%p.log -XX:InitialHeapSize=16777216 -XX:MaxHeapSize=1073741824 -XX:+PrintGC -XX:+PrintGCTimeStamps -XX:-UseLargePagesIndividualAllocation
0.322: [GC (Allocation Failure) 4416K->1040K(15872K), 0.0043299 secs]
0.398: [GC (Allocation Failure) 5456K->3128K(15872K), 0.0035010 secs]
0.480: [GC (Allocation Failure) 7544K->4146K(15872K), 0.0033180 secs]
0.508: [GC (Allocation Failure) 8562K->4319K(15872K), 0.0028429 secs]
0.515: [GC (Allocation Failure) 8726K->4362K(15872K), 0.0014477 secs]
0.546: [GC (Allocation Failure) 8778K->5109K(15872K), 0.0023394 secs]
0.571: [GC (Allocation Failure) 9525K->5040K(15872K), 0.0018788 secs]
0.619: [GC (Allocation Failure) 9456K->6239K(15872K), 0.0045714 secs]
0.639: [GC (Allocation Failure) 10655K->9123K(15872K), 0.0026407 secs]
0.653: [GC (Allocation Failure) 13539K->12218K(16640K), 0.0025906 secs]
0.656: [Full GC (Allocation Failure) 12218K->12218K(16640K), 0.0091288 secs]
0.694: [GC (Allocation Failure) 19579K->16967K(28348K), 0.0058126 secs]
0.722: [GC (Allocation Failure) 24834K->22086K(30052K), 0.0046649 secs]
0.727: [Full GC (Allocation Failure) 22086K->22086K(30052K), 0.0112068 secs]
0.778: [GC (Allocation Failure) 35490K->30043K(51368K), 0.0098116 secs]
0.830: [GC (Allocation Failure) 44315K->34207K(51368K), 0.0127499 secs]
0.882: [GC (Allocation Failure) 48479K->38497K(52776K), 0.0119572 secs]
0.894: [Full GC (Allocation Failure) 38497K->38497K(52776K), 0.0277656 secs]
1.057: [GC (Allocation Failure) 61409K->43770K(88932K), 0.0232897 secs]
1.567: [GC (Allocation Failure) 68410K->49161K(88932K), 0.0228224 secs]
1.774: [GC (Allocation Failure) 73801K->54209K(88932K), 0.0144856 secs]
2.660: [Full GC (Metadata GC Threshold) 69102K->42564K(88932K), 0.0449064 secs]
3.355: [GC (Allocation Failure) 71044K->47328K(102944K), 0.0108748 secs]
3.904: [GC (Allocation Failure) 75808K->52938K(102944K), 0.0210788 secs]
4.027: [GC (Allocation Failure) 81418K->56317K(102944K), 0.0125392 secs]
4.355: [GC (Allocation Failure) 84797K->57277K(102944K), 0.0092810 secs]
4.707: [GC (Allocation Failure) 85757K->60982K(102944K), 0.0120037 secs]
5.090: [Full GC (Metadata GC Threshold) 75873K->58456K(102944K), 0.0899523 secs]
6.323: [GC (Allocation Failure) 97496K->67513K(141332K), 0.0300465 secs]
7.357: [GC (Allocation Failure) 102999K->78400K(141332K), 0.0350410 secs]
7.672: [Full GC (Metadata GC Threshold) 87567K->65335K(141332K), 0.1162865 secs]
9.394: [GC (Allocation Failure) 108983K->70979K(157984K), 0.0274511 secs]
10.300: [GC (Allocation Failure) 114627K->74486K(157984K), 0.0302167 secs]
10.983: [GC (Allocation Failure) 118134K->76286K(157984K), 0.0271287 secs]
11.780: [GC (Allocation Failure) 119934K->79470K(157984K), 0.0233156 secs]
13.111: [GC (Allocation Failure) 123118K->81341K(157984K), 0.0249988 secs]
13.268: [Full GC (Metadata GC Threshold) 85218K->66155K(157984K), 0.2353434 secs]
14.551: [GC (Allocation Failure) 110379K->69711K(159988K), 0.0204552 secs]
15.486: [GC (Allocation Failure) 113935K->71958K(159988K), 0.0192550 secs]
16.629: [GC (Allocation Failure) 116182K->75935K(159988K), 0.0278797 secs]
17.686: [GC (Allocation Failure) 120159K->83147K(159988K), 0.0294754 secs]
18.268: [GC (Allocation Failure) 127371K->94111K(159988K), 0.0380868 secs]
18.725: [GC (Allocation Failure) 138335K->105327K(159988K), 0.0443552 secs]
23.391: [GC (Allocation Failure) 149551K->113632K(159988K), 0.0503248 secs]
57.356: [GC (Allocation Failure) 157856K->118215K(163324K), 0.0372537 secs]
57.394: [Full GC (Allocation Failure) 118215K->78406K(163324K), 0.2369982 secs]
92.345: [GC (Allocation Failure) 130821K->81545K(189624K), 0.0168981 secs]
117.588: [GC (Allocation Failure) 133961K->82092K(189624K), 0.0214815 secs]
139.777: [GC (Allocation Failure) 134508K->82945K(189624K), 0.0225465 secs]
219.740: [GC (Allocation Failure) 135361K->82582K(189624K), 0.0140721 secs]
Binary file added homework/heap_dump_compare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added homework/jvmgc_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added homework/jvmgc_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added homework/jvmgc_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions homework/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<mirrors>
<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<localRepository>/home/bill/.m2/repository<localRepository>
</settings>
60 changes: 46 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,73 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.4.5</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.5</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>2.5.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0.1</version>
<groupId>com.github.springtestdbunit</groupId>
<artifactId>spring-test-dbunit</artifactId>
<version>1.2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0.1</version>
</dependency>
</dependencies>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

</dependencies>

</project>
</project>
37 changes: 37 additions & 0 deletions src/main/java/com/epam/data/EnrichRoadAccident.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.epam.data;

import java.time.LocalTime;

/**
* Created by bill on 16-5-2.
*/
public class EnrichRoadAccident extends RoadAccident {
private String ForceContact;
private TimeOfDay timeOfDay;

public EnrichRoadAccident(RoadAccidentBuilder builder) {
super(builder);
}

/*
public EnrichRoadAccident(RoadAccident roadAccident) {
super(builder);
}
*/

public String getForceContact() {
return ForceContact;
}

public void setForceContact(String forceContact) {
ForceContact = forceContact;
}

public TimeOfDay getTimeOfDay() {
return timeOfDay;
}

public void setTimeOfDay(LocalTime time) {
this.timeOfDay = TimeOfDay.getTimeOfDay(time);
}
}
31 changes: 31 additions & 0 deletions src/main/java/com/epam/data/RoadAccident.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,35 @@ public String getRoadSurfaceConditions() {
public void setRoadSurfaceConditions(String roadSurfaceConditions) {
this.roadSurfaceConditions = roadSurfaceConditions;
}

// Patch for home work 3, should extend RoadAccident class
private String ForceContact = null;
private TimeOfDay timeOfDay;

public String getForceContact() {
return ForceContact;
}

public void setForceContact(String forceContact) {
ForceContact = forceContact;
}

public TimeOfDay getTimeOfDay() {
return timeOfDay;
}

public void setTimeOfDay(LocalTime time) {
this.timeOfDay = TimeOfDay.getTimeOfDay(time);
}

public String toCSV() {
return String.join(",",
accidentId,
policeForce,
ForceContact,
time.toString(),
timeOfDay.toString()
);
}

}
50 changes: 50 additions & 0 deletions src/main/java/com/epam/data/TimeOfDay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.epam.data;

import java.time.LocalTime;

/**
* Created by bill on 16-5-2.
*
*/

public enum TimeOfDay {
MORNING, AFTERNOON, EVENING, NIGHT;

public static TimeOfDay getTimeOfDay(LocalTime time) {
int hour = time.getHour();
switch (hour/6) {
case 0:
return TimeOfDay.NIGHT;
case 1:
return TimeOfDay.MORNING;
case 2:
return TimeOfDay.AFTERNOON;
case 3:
default:
return TimeOfDay.EVENING;
}
}

public int getCategory() {
if(this.equals(TimeOfDay.MORNING) | this.equals(TimeOfDay.AFTERNOON)) {
return 1;
} else {
return 0;
}
}
}

/*
MORNING - 6 am to 12 pm
AFTERNOON - 12 pm to 6 pm
EVENING - 6 pm to 12 am
NIGHT - 12 am to 6 am
MORNING,
AFTERNOON(AFTERNOON"),
EVENING("EVENING"),
NIGHT("NIGHT");
MORNING,
AFTERNOON,
EVENING,
NIGHT;
*/
10 changes: 8 additions & 2 deletions src/main/java/com/epam/dataservice/AccidentBatchLoader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.epam.dataservice;


import com.epam.data.EnrichRoadAccident;
import com.epam.data.RoadAccident;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
Expand All @@ -13,9 +14,12 @@
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;

public class AccidentBatchLoader implements Callable<Integer> {

private static AtomicInteger serialNo = new AtomicInteger();
private String taskName = this.getClass().getSimpleName() + serialNo.incrementAndGet();
private Integer batchSize;
private BlockingQueue<List<RoadAccident>> dataQueue;
private String dataFileName;
Expand All @@ -42,11 +46,13 @@ public Integer call() throws Exception {
dataCount = dataCount + roadAccidentBatch.size();
if(roadAccidentBatch.isEmpty()){
isDataLoadFinished = true;
System.out.println(taskName + " Finished");
}else{
++batchCount;
System.out.println(" Completed reading " + dataCount + " in " + batchCount + " batches for " + dataFileName);
// System.out.println(taskName + " Trying to put, Queue.remainingCapacity()="+dataQueue.remainingCapacity());
dataQueue.put(roadAccidentBatch);
}
dataQueue.put(roadAccidentBatch);
}
//dataQueue.put(roadAccidentBatch); //Epmty batch can be used as identifier for end of record production
return dataCount;
Expand All @@ -61,7 +67,7 @@ private List<RoadAccident> getNextBatch(Iterator<CSVRecord> recordIterator){
List<RoadAccident> roadAccidentBatch = new ArrayList<RoadAccident>();
int recordCount = 0;
RoadAccident roadAccidentItem = null;
while(recordCount <= batchSize && recordIterator.hasNext() ){
while(recordCount < batchSize && recordIterator.hasNext() ){
roadAccidentItem = roadAccidentParser.parseRecord(recordIterator.next());
if(roadAccidentItem != null){
roadAccidentBatch.add(roadAccidentItem);
Expand Down
Loading